1.0.1 • Published 1 year ago

with-props-hoc v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

withProps

npm version build Test codecov

Higher order component to inject a subset of props for code reuse with TypeScript type declaration.

About

import React from 'react'

const withProps = (Composed, props) => own => <Composed {...{ ...props,...own }}>{own.children}</Composed>

Improvements over this one-liner are :

  • Non-react statics methods are copied over using hoist-non-react-statics.

  • ref is forwarded to the component being wrapped

  • displayName will appear as

`withProps${Component.displayName}`
  • TypeScript type declaration

⚠ Be aware of other HOC caveats when using this. ⚠

Usage

import withProps from 'with-props-hoc'

const NewComponent = withProps(SourceComponent, props)
1.0.1

1 year ago

1.0.0

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago