DEV Community

Sakthi S
Sakthi S

Posted on

What is Use State?

  • The useState hook is a fundamental function in React that allows you to add state variables to functional components.

  • State refers to data or properties that need to be tracked and updated in an application, and useState enables components to "remember" information between re-renders, making the user interface dynamic and interactive.

  • const [state, setState] = useState(initialState)

useState(initialState)

Call useState at the top level of your component to declare a state variable.


`import { useState } from 'react';

function MyComponent() {
  const [age, setAge] = useState(28);
  const [name, setName] = useState('Taylor');
  const [todos, setTodos] = useState(() => createTodos());`
Enter fullscreen mode Exit fullscreen mode

Top comments (0)