Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controlled components not possible #26

Open
aidanhs opened this issue Jan 27, 2019 · 2 comments
Open

Controlled components not possible #26

aidanhs opened this issue Jan 27, 2019 · 2 comments

Comments

@aidanhs
Copy link

aidanhs commented Jan 27, 2019

See yewstack/yew#233 (comment) for context.

Essentially, the desired behavior is: if an edit for a field (e.g. an input or text area) is 'rejected' (i.e. not applied to the model), the render should not update. In react this is known as 'controlled components'.

In squark you can test this by applying the patch I've pasted at the bottom and then editing the 'new item' input element on the todomvc example. Because the internal state isn't changing, arguably neither should the render. Unfortunately, it does.

React solves this by restoring state after a change event (described on the linked issue). Note that react also provides uncontrolled components where the value field is not set. I think the important thing is that both options are available (somehow).

diff --git a/examples/todomvc/crate/src/lib.rs b/examples/todomvc/crate/src/lib.rs
index a97c915..f640e85 100644
--- a/examples/todomvc/crate/src/lib.rs
+++ b/examples/todomvc/crate/src/lib.rs
@@ -187,10 +187,10 @@ fn header_view(state: &State) -> View<Action> {
                 class="new-todo"
                 placeholder="What needs to be done?"
                 value={ state.field.clone() }
-                oninput={ |v| match v {
-                    HandlerArg::String(v) => Some(Action::UpdateField(v)),
-                    _ => None,
-                } }
+                //oninput={ |v| match v {
+                //    HandlerArg::String(v) => Some(Action::UpdateField(v)),
+                //    _ => None,
+                //} }
                 onkeydown={ |v| match v {
                     HandlerArg::String(ref v) if v.as_str() == "Enter" => Some(Action::Add),
                     _ => None,
@rail44
Copy link
Owner

rail44 commented Jan 28, 2019

@rail44
Copy link
Owner

rail44 commented Jan 28, 2019

Hmm. We have a simple binding for DOM such as just string base.
Before wrapping DOM to implement Comtrolled Component, We must make the binding having more rich types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants