Apply for Zend Framework Certification Training

ReactJs






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 = () =>{
        setMyName('Sujeet');
    };
    const reverseName = () =>{
        setMyName('Rajesh');
    };
    return(
        <div>
            <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>
            </p>
        </div>
 
    );
 
}
export default UseStateExample;

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



Ask a question



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


Back to Top