I wanted to setState with react hooks usestate.
First I tried. but it not worked.
const [action, setAction] = useState(null);
...
<button onClick={()=>{
setAction(()=>{console.log('hi')})
}}>test</button>
Second. It worked.
const [action, setAction] = useState({action: null});
...
<button onClick={()=>{
setAction({
action:()=>{
console.log('hi')
}
})}
}>test</button>
Because if I set function directly, the state changed to undefined.
So I pass the function with object type.
But I want to know if there is another way to set state with function.