Skip to content
public-library›Rules›React›Initialize expensive state lazily

Initialize expensive state lazily

When the initial state comes from a computation, pass a function to useState, such as useState(() => buildIndex(items)), instead of the computed value.

In the full rule