I really like the new React hooks and I'm using them frequently for a project I'm working on. I'm coming across a situation where I want to use the prevState in the useState
hook, but I'm not really certain on how to do this.
I've tried something like this, but it fails to compile.
const [ someState, setSomeState ] = useState( new Map() )
setSomeState( prevState.someState.set( key, value ) )
(by the way, this is to map an array of checkboxes to keep track of the ones that are check marked)
I'm trying to follow this example here, but without using the setState
function.
Map
example. While this works, it may be less performant than other alternatives (especially if theMap
becomes large). – Canna