DEV Community

Discussion on: Update boolean state right with React Hooks

Collapse
 
juangabrieldev profile image
Juan Gabriel Palarpalar

You can provide a callback for useState that accepts the current state.

setIsToggled(state => !state)

I don't get why you have to use refs for this.

Collapse
 
alexkhismatulin profile image
Alex Khismatulin

You're 100% right, there's no need to mess with refs in this case. I totally forgot about the functional state update. I'm going to add a note about that. Thank you!