React.memo polyfill
- What: https://reactjs.org/docs/react-api.html#reactmemo
- Why: https://medium.com/@trekinbami/using-react-memo-and-memoization-1970eb1ed128
- When: React.memo was introduced in [email protected]. You can use this polyfill until you upgrade your components
$ yarn add react-memo-polyfill
import memo from 'react-memo-polyfill'
function MyComponent(props) { }
memo(MyComponent)
Optionally pass your compare function
import memo from 'react-memo-polyfill'
function MyComponent(props) { }
function areEqual(prevProps, nextProps) {
/*
return true if passing nextProps to render would return
the same result as passing prevProps to render,
otherwise return false
*/
}
export default memo(MyComponent, areEqual);