manx-cli 0.5.9

A blazing-fast CLI documentation finder powered by Context7 MCP
Documentation
# React Hooks Guide

## useState Hook

The useState hook allows you to add state to functional components. It returns an array with two elements: the current state value and a function to update it.

```javascript
import React, { useState } from 'react';

function Counter() {
  const [count, setCount] = useState(0);
  
  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
```

## useEffect Hook

The useEffect hook lets you perform side effects in functional components. It serves the same purpose as componentDidMount, componentDidUpdate, and componentWillUnmount combined.

```javascript
import React, { useState, useEffect } from 'react';

function Example() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    document.title = `You clicked ${count} times`;
  });

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
```

## State Management Best Practices

- Keep state minimal and derived values computed
- Use useState for simple local state
- Consider useReducer for complex state logic
- Lift state up when sharing between components