So, stateless function components should âalwaysâ be pure components, why isnât this the default behavior ? It would have been great if this was implemented from the start , so people know very well the consequences and always relate âfunctionâ to âpureâ. However, maybe this can get done in a new React version? If you do a major version upgrade you have to know that maybe some things will break. So this would be ok. Of course, I would also ask to remove React.memo in React 17
The reason (AFAIK) is that doing the memo check is not free. for most components checking prev and next props for differences every render and maybe skipping a render would be ultimately be slower than just always rerendering. That's why it's opt in, giving the user the option to optimize the components that would benefit from memo.
@jquense remember that âalways renderingâ is not literally true. React does a check in the virtual dom, to see if the things your component returned changed, if they do, it does the rendering in the real dom. Pure components would not need this check, since youâre saying âI want to be re-rendered if my props changed, donât even check this virtual dom!â. The question is: Is checking the props slower than checking the virtual dom ? (I donât know if this is the actual behavior, tho. Maybe the virtual dom check is obligatory)
Hi đ This would be a large change. As such, it would need to go through our RFC process: https://github.com/reactjs/rfcs/
I'm going to close this issue đ
Most helpful comment
The reason (AFAIK) is that doing the memo check is not free. for most components checking prev and next props for differences every render and maybe skipping a render would be ultimately be slower than just always rerendering. That's why it's opt in, giving the user the option to optimize the components that would benefit from
memo.