0% found this document useful (0 votes)
16 views

Function That Updates State Variable Initial Value of State Variable

useState allows components to add state to function components by taking in an initial state value and returning a state variable and function to update it; setState triggers a re-render by updating the state variable value.

Uploaded by

Ruben Gutierrez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Function That Updates State Variable Initial Value of State Variable

useState allows components to add state to function components by taking in an initial state value and returning a state variable and function to update it; setState triggers a re-render by updating the state variable value.

Uploaded by

Ruben Gutierrez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

useState

React’s useState Hook

function that
updates state initial value of
variable state variable

const [state, setState] = useState(initialState);


State variable

Initialize and use state variable

initialize state variable

render state variable

Initialize state variable with function

initialize value of state


variable with function

Update value of state variable

destruct function to
update state variable

trigger function to
update state variable

Update value of state variable with previous


state value

use the functional


update form of the
update state function.


Function passed in
has access to the
previous state value.

You might also like