Skip to main content

Command Palette

Search for a command to run...

How do you update a React state (hooks)?

Updated
1 min readView as Markdown
How do you update a React state (hooks)?

There is 2 ways for updating state: 1st method :

const ap = ( event ) =>  {
        setUser({  ...user ,  enteredUser : event.target.value });
    }

2nd method (the best) :

const ap  =  (event) =>  {
        setUser(( prevState )  => {
            return { ...prevState , enteredUser : event.target.value };
        });

More from this blog

Omar's blog

135 posts