Apply for Zend Framework Certification Training


a) What is the useState Hook?
The state of your application is bound to change at some point. 
This could be the value of a variable, an object, or whatever 
type of data exists in your component.
To make it possible to have the changes reflected in the DOM, 
we have to use a React hook called useState. It looks like this:
import { useState } from "react";
function UseStateExample(){
    const [myname,setMyName] = useState('Rajesh');
    const changeName = () =>{
    const reverseName = () =>{
            <p align="center"><b> My name is {myname} </b></p>
            <p align="center">
                <button onClick={changeName}>Click me</button>
                <button onClick={reverseName}>Reverse me</button>
export default UseStateExample;

< react form using onchange and useState create accordion in reactJs >

Ask a question

  • Question:
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question

Back to Top