Reactjs Hooks With State Example

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Today now in this blog i will talk with you about the reactjs hooks. We know hooks is introduce in react js 16.8 varsion. So we can use hooks in above 16.8 version in reactjs. Now they let we use state and also other React features without writing a class component. So we can also use life cycle method by using hooks. We know that hooks only work in functional component it is not work in class component.

Hooks With State Example

Now in this following example we can see first we need to use state in component at first we have to define in import like “useState”. And then we need to define a variable then we can use it.

/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;

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →