ReactHooks -Tutorial - 2 - useState (String)

Опубликовано: 13 Июль 2026
на канале: Svr techSolutions
59
1

useState() Functional Component
With a functional component, we can use React hooks, specifically the useState() hook. This simplifies the creation of a state component and the function that updates it.

We import {useState} from React and we are able to simply create a state and a function to set that state (state: value, setState: setValue). The initial state of this component is set when calling useState, in this example, we are setting it to an empty string (useState("")). The only difference between the functional component and the class component at this point is instead of calling this.setState we use the function we created in the useState, in this case, setValue.