Better Programming

Advice for programmers.

Follow publication

10 Tips and Tricks to Boost Your React App’s Performance in 2020

Harsh Makadia
Better Programming
Published in
7 min readAug 31, 2020
Icons by Freepik on flaticon.

1. Pause Console Debugger

setTimeout(() => {debugger;}, 5000)
Stop debugger — Credit: ralex1993

2. useState Lazy Initialization With Function

const initialState = someFunctionThatCaluclatesValue(props)const [count, setCount] = React.useState(initialState)
const getInitialState = (props) => someFunctionThatCaluclatesValue(props)const [count, setCount] = React.useState(getInitialState)
Lazy function vs. ordinary function
Example on CodeSandbox

3. Making Use of Custom Hooks

this.setState({
"name" : "Harsh"
}, () => {
// Hey that state is set successfully what do you
// want to do, I'm callback your friend 😄
})

4. Monitor Unnecessary Renders in Your Applications

why-did-you-render

Image credit: GitHub.

React Devtools

Start recording
Rendering information

5. Using React.memo and useMemo

This will result in re-rendering.

6. Deep Comparison in shouldComponentUpdate

7. React Window

8. React Query

Example from GitHub.

9. Lazy Loading React Components (With React.lazy and Suspense)

What is React.lazy( )?

What is Suspense?

10. One Function to Update Multiple Input State Values

Conclusion

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Harsh Makadia
Harsh Makadia

Written by Harsh Makadia

I talk about JavaScript, Web Development, No-code to help you stay ultra-modern. See you on Twitter — https://twitter.com/MakadiaHarsh