Explain State Hook with an example?

Answer

State Hooks are primarily used to refer to the states of the components in React and can be used to change them on the runtime as per the functionality of your web application. An example below increments a counter on click of a button:
function Counter() {

const [count, setCount] = useState(0)

return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Increment Counter
</button>
</div>
)
}

All react js Questions

Ask your interview questions on react-js

Write Your comment or Questions if you want the answers on react-js from react-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---