1

React gives a way to memoize the components using React.memo which actually stops the component re-render if there is no change in props.

import React, { memo } from 'react'; interface ComponentNameProps { } const ComponentName:React.FC<ComponentNameProps> = props => { const {} = props; return ( <div> </div> ) } export default memo(ComponentName) 

Do we put all our component into memo, will it be a good practise?

2
  • React.memo is used to memoize heavy calculations. I don't think what you are trying to do is good practice. Commented Aug 20, 2021 at 7:18
  • This might be useful, checkout this answer stackoverflow.com/questions/53074551/… Commented Aug 20, 2021 at 7:21

2 Answers 2

1

Well, if you use React.memo, everytime you use the component react is gonna run a compare function to see if the props have changed; so if redeclaring your function is less expensive, then you are hurting the performance, rather than improving it. so it's a tradeoff that sometimes is worth making, but not for every component.

Sign up to request clarification or add additional context in comments.

Comments

-1

No, it is not a good practice. In fact, overusing useMemo can hurt your application more (performance-wise) than the re-renders.

Please use wisely and with caution.

Read more about it here.

1 Comment

useMemo is not the same thing as React.memo. Also the performance considerations are quite different.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.