-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[📖] explain uncontrolled vs controlled components #6336
Comments
Just for more context, in Vue it would be something like that: //uncontrolled -> behaves like vanilla html
<input type="checkbox" checked={true} />
//controlled (one way data-binding)
const acceptConditions = useRef(false);
<input
:checked="acceptConditions"
@change="event => acceptConditions = event.target.checked"
">
//controlled (two way data-binding = syntactic sugar to achieve above behavior)
const acceptConditions = useRef(false);
<input type="checkbox" v-model="acceptConditions"> |
shouldn't we follow the same pattern as |
To be honest, even I am confused about the Qwik is modeled after normal html, except for the bind syntax. There is confusion when migrating no matter which ecosystem you look at, because other JSX frameworks decided they were going to do something different. (cough React) See: for more context |
|
My understanding is that the |
Suggestion
Perhaps tbd in /guides/react-cheat-sheet
Uncontrolled vs controlled
In Qwik, the
value
prop by default behaves like the vanilla htmlvalue
attribute. So the pattern is the following:React provides
defaultValue
,defaultOpen
,defaultToggled
, etc. props to enable "uncontrolled" inputs for when you want your inputs to work with vanilla html forms. This is because if you just set avalue
attribute like in vanilla html it will be interpreted as a controlled component by React and won't work. You have to also set anonChange
event handler to express how to update the state the other way around.The React pattern is the following:
Consistency recommendation for reusable components:
To keep your APIs consistent in Qwik Land, we recommend using the Qwik input patterns on your reusable components. For example:
TODO:
The text was updated successfully, but these errors were encountered: