-
Anyone coming from React is familiar with controlled components. As I was working through building the thinkster realworld demo, I was able to remove the I'm wondering if I'm missing something? If not, I think we should add a "controlled components" section to the docs as it's a breath of fresh air Demo Login Form: https://codesandbox.io/s/busy-haze-ypse4?file=/src/index.js function* Login() {
let email = "";
let password = "";
const onEmailChange = e => {
email = e.target.value;
};
const onPasswordChange = e => {
password = e.target.value;
};
const onSubmit = e => {
e.preventDefault();
console.log(email, password);
};
while (true) {
yield (
<form onsubmit={onSubmit}>
<input type="email" placeholder="Email" oninput={onEmailChange} />
<input
type="password"
placeholder="Password"
oninput={onPasswordChange}
/>
<button type="submit">Sign in</button>
</form>
);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
So FWIW I don't need to use a generator here if I don't expect this component to render after the first yield. The generator brings value if I want to safely maintain the While this works in React land, you never do it because those values aren't state and get blown away on every re-render. |
Beta Was this translation helpful? Give feedback.
So FWIW I don't need to use a generator here if I don't expect this component to render after the first yield. The generator brings value if I want to safely maintain the
email
andpassword
values as state over subsequent updates to the component (like prop updates).While this works in React land, you never do it because those values aren't state and get blown away on every re-render.