Reactjs Hooks With State Example
Jan 23, 2020
Hello Guys,
Today we are learing about reactjs hooks. hooks introduce in react js 16.8 varsion. you can use hooks in above 16.8 varsion in reactjs. They let you use state and other React features without writing a class component. you can also use life cycle method using hooks. hooks only work in functional component it not work in class component.
Hooks With State Example
In following example you can see first you have to use state in component first you hav to defin in import like "useState". then you have to define variable then you can use.
/src/App.js file
import React,{useState} from 'react';
function App(){
const [count, setCount] = useState(0);
return(
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
)
}
export default App;
- How to Reactive Forms with Validation in Angular 18?
- Reactjs Props Example With Function and Class Components
- React Color Picker Example With Change Event
- How to Hide and Show Multiple Div in React ?
- React js File Upload Example With Axios
- How to Resize, Crop, Compress Images Before Uploading In ReactJS?
- How to Send Data From React to Node JS Express?
- Reactjs String Replace Example