Open in app
Thiyagaraj T
132 Followers
About

Sign in

132 Followers
About
Open in app

React useState lazy initialization in one glance

Thiyagaraj T

Thiyagaraj T

·Nov 17, 2020

Photo by Anne Nygård on Unsplash

How

useState is the simplest React hook out in wild but it has a very interesting feature — lazy initialization

If you provide useState with a function, then it will be executed only on the initial render.

When to use

Any function that is computationally expensive can be initialized lazily.

Reference

  • https://reactjs.org/docs/hooks-reference.html#usestate

  • React
  • React Hook
  • Hooks

More from Thiyagaraj T

Frontend at DgraphLabs

More From Medium

4 simple steps you can take now to improve your TypeScript codebase

Manon Jacquin in Weekly Webtips

Basic Webpack setup — Part 2

Marina in Comida For Familias, Inc.

Interpolation with React Native Animations

evening kid

The Best JavaScript Courses On Udemy (2021)

Gyan Kumi in Course Hunt

Using Prettier and ESLint in VSCode

João Vitor

Functional Programming in JavaScript

Alex Motor

What Are Higher Order Array Methods in JavaScript?

Rajat M in Weekly Webtips

Noobs Guide: Javascript vs JQuery vs ECMAScript vs Typescript

Brenn

About

Help

Legal

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store