> For the complete documentation index, see [llms.txt](https://olga-f.gitbook.io/react/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olga-f.gitbook.io/react/how-to-avoid-expensive-re-calculating.md).

# How to avoid expensive re-calculations

React has a built-in hook called  useMemo that allows you to memoize expensive functions so that you can avoid calling them on every render.

> Memoization is an optimization strategy that returns cached values from functions that have previously been invoked with the same arguments. In other words, instead of recalculating its return value, the function will return a cached value. This is useful when you have functions doing memory intensive operations and want to minimize how often they're invoked.

```jsx
 const allItems = getItems(inputValue)
```

change to&#x20;

```jsx
const allItems = React.useMemo(() => getItems(inputValue), [inputValue])
```
