Input and hooks #1142
-
Hi, so we got a load of form like elements like e.g.: Input However, how does one make it really useful by binding it to a property using hooks? e.g.: How to bind this input to that useState? One cant even use the regular onChange since the events there are useless CustomEvents without any access to value ... with typescript its locked tight
while in normal react is it as easy as this:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Hey @kbachl, it should be almost the same with our Input component: you can access the current value via const MyComponent = () => {
const [value, setValue] = useState("");
const onInputChange = useCallback(
(event) => {
setValue(event.target.value);
},
[setValue]
);
return <Input value={value} onInput={onInputChange} />;
}; This sample would update the You can also omit the I hope this helps 🙂 |
Beta Was this translation helpful? Give feedback.
Hey @kbachl,
it should be almost the same with our Input component: you can access the current value via
event.target.value
:This sample would update the
value
on every keystroke in the input, you can useonChange
if you want to update it only once after the input looses focus.You can also omit the
useCallback
if you want to, that's just a performance optimization.I hope this helps 🙂