Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

to-hoc

0.0.0-alpha.1 • Public • Published

ToHoc

Convert render props to higher order components.

// Takes a render prop, like <RenderButts render={({ butts }) => } />
const RenderButts = ({render}) =>
  <div>{render({butts: 'many'})}</div>
 
// Convert it to a higher order component
const WithButts = ToHoc(RenderButts)
 
// Helper component that renders all its props as a list
const ShowProps = (props) =>
  <ul>
    {Object.keys(props).map(x => <li>{x}: {JSON.stringify(props[x])}</li>)}
  </ul>
 
const ShowButts = WithButts(ShowProps)

Now we have ShowButts that's wrapped in a WithButts higher order component. This is essentially the code from react-router's WithRouter HOC, but generalized for any component that expects a render prop.

Keywords

none

Install

npm i to-hoc

DownloadsWeekly Downloads

1

Version

0.0.0-alpha.1

License

MIT

Last publish

Collaborators

  • avatar