I see myself using declarations like:
const [state, setState] = React.useState({value: ''});
return <InputComponent {...properties} value={state.value} onChange={(event) => setState({value: event.target.value || event.target.checked}
Whenever a component needs state I have to rewrite this down and it feels not reusable at all. I looked for render props and HOC, but couldn't reuse state.
I tried creating:
const StatefulInput = (InputComponent) => {
const [state, setState] = React.useState({value: ''});
return <InputComponent value={state.value} onChange={(event) => setState({value: event.target.value || event.target.checked />
}
But I couldn't reuse, I got 'invalid Hook', 'render received object not something else' errors and some other ones.
How can I do it? Is it possible to reuse this hook?