Skip to content

React Utils - v2.3.0

Choose a tag to compare

@ItsJonQ ItsJonQ released this 11 Mar 17:03
· 4 commits to master since this release

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 componentDidUpdate lifecycle 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} />
})

v2.2.0...v2.3.0