---
url: /docs/guide/usage/linter/rules/react/purity.md
---

### What it does

Validates that components and hooks are pure by checking that they do
not call known-impure functions such as `Math.random()`, `Date.now()`,
or `performance.now()` during render.

Async function components are exempt, including impure calls in nested
callbacks. An async component is a Server Component: it renders once per
request and does not re-render. Async hooks are still checked.

Powered by the React Compiler, which runs once per file and is shared
with the other React Compiler rules. Port of
[`react-hooks/purity`](https://react.dev/reference/eslint-plugin-react-hooks/lints/purity).

### Why is this bad?

Impure renders return different output for the same props and state,
breaking memoization, concurrent rendering, and replayability.

### Examples

Examples of **incorrect** code for this rule:

```jsx
function Component() {
  const rand = Math.random();
  return <div>{rand}</div>;
}
```

Examples of **correct** code for this rule:

```jsx
import { useState } from "react";
function Component() {
  const [rand, setRand] = useState(0);
  return <button onClick={() => setRand(Math.random())}>{rand}</button>;
}

async function Posts({ posts }) {
  return (
    <ul>
      {posts.map((post) => (
        <li key={post.id}>{Date.now()}</li>
      ))}
    </ul>
  );
}
```

## How to use

## Version

This rule was added in v1.79.0.

## References
