Can I directly pass setState
to onChangeText
in TextInput
component instead of passing a callback function and calling setState
function in a callback? e.g
const [state, setState] = useState(initialState);
/*Other code logic*/
<TextInput onChange={setState}/>
CodePudding user response:
Yes, you can directly trigger functions. E.g.:
const [state, setState] = useState(initialState);
/* Other code logic */
<TextInput onChangeInput={(evt) => {
setState(evt.target.value)
} />