DEV Community

dannohh
dannohh

Posted on

1

React Hooks and state

With React Hooks, we can give our functional components some state to keep track of and render() with said component or even children components. To do this we can use the useState() hook to set our initial state and the setState() method for updating. When we want to do something AFTER our component renders for the first time, (Mounts) we can use the useEffect() method. So, we set the initial state of our component with the useState() method and update the state with the setState() method.

Being able to manipulate and set the state of our functional components allows more freedom and flexibility while building or Apps with React. For example, when we want a small component to be able to keep track of, and update its own state without rendering it through a parent component, we could use a hook instead of the traditional Class component with a constructor, saving time, space and making our code easier to read for humans! Sweet!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay