Skip to content

Simple Higher Order Component to inject an initialised set of props in a component

License

Notifications You must be signed in to change notification settings

jeremy-faton/with-props

Repository files navigation

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)

About

Simple Higher Order Component to inject an initialised set of props in a component

Resources

License

Stars

Watchers

Forks

Packages

No packages published