React Utils - v2.3.0
Add Memo HOC
This update adds a new HOC called memo, which is an enhanced polyfill for the new React memo API.
This version of memo works just like React.memo, but is backwards compatible.
The enhancements include:
- A third argument that provides a
componentDidUpdatelifecycle callback - Hoists statics by default
Memo allows you to performantly created stateless-functional components, as it has a (shallow) prop comparison mechanism that protects the SFC from re-renders.
Examples
import React from 'react'
import memo from '@helpscout/react-utils/dist/memo'
const Kip = props => <div {...props} />
const MemoizedKip = memo(Kip)Alternatively...
import React from 'react'
import memo from '@helpscout/react-utils/dist/memo'
const MemoizedKip = memo(function Kip(props) {
return <div {...props} />
})