Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Memo HOC #18

Merged
merged 4 commits into from
Mar 11, 2019
Merged

Add Memo HOC #18

merged 4 commits into from
Mar 11, 2019

Conversation

ItsJonQ
Copy link
Contributor

@ItsJonQ ItsJonQ commented Mar 11, 2019

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

@ItsJonQ ItsJonQ added the enhancement New feature or request label Mar 11, 2019
@ItsJonQ ItsJonQ self-assigned this Mar 11, 2019
@coveralls
Copy link

coveralls commented Mar 11, 2019

Pull Request Test Coverage Report for Build 72

  • 19 of 19 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 69: 0.0%
Covered Lines: 191
Relevant Lines: 191

💛 - Coveralls

Copy link

@tinkertrain tinkertrain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!! :shipit:

@ItsJonQ ItsJonQ merged commit 8be56c2 into master Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants