1. Declaring Multiple state variables
We can declare multiple state variables by calling useState multiple times
JSX
2. Initializing State
Syntax:
JSX
The initial value provided to the useState() can be of any data type
2.1 Providing Object as an initial value
As a best practice, we can provide Object as an initial value when we want to store values that tend to change together
Example:
JSX
2.2 Providing Array as an initial value
We can provide the array as an initial value to useState()
JSX
3. Updating State
We can update the state using setter function by passing value/callback function as an argument
JSX
3.1 Updating State using Callback function
Update the state using callback function if the next state is computed based on the previous state
JSX
File: src/components/Comments/index.js
JSX
4. Video Streaming Application Code
Use the below command to get the Final Code for Video Streaming Application
SHELL
Tags:
React Hooks