useState in react.js simple example
In this example, we import the useState hook from the React library. Inside the Example functional component, we declare a state variable called "count" using the useState hook. The initial value of count is set to 0. We also define a function called handleClick, which increments the count state by 1 when the button is clicked. The setCount function provided by the useState hook is used to update the value of count. Finally, we render the current value of count in a paragraph element, and a button that triggers the handleClick function when clicked. When the button is clicked, the component re-renders with the updated value of count, and the new count is displayed on the screen.
In this example, we import the useState hook from the React library. Inside the Example functional component, we declare a state variable called "count" using the useState hook. The initial value of count is set to 0. We also define a function called handleClick, which increments the count state by 1 when the button is clicked. The setCount function provided by the useState hook is used to update the value of count. Finally, we render the current value of count in a paragraph element, and a button that triggers the handleClick function when clicked. When the button is clicked, the component re-renders with the updated value of count, and the new count is displayed on the screen.