react-render-with-params icon indicating copy to clipboard operation
react-render-with-params copied to clipboard

The render method you've always wanted

Build Status

react-render-with-params

I've been using Preact recently and I loved the way props, state and context are passed to the render method. It feels like writing functional components and it's great for destructuring.

That's what the renderWithParams higher order component is about.

Installation

npm i react-render-with-params --save

Usage

import React, { PropTypes } from 'react'
import { render } from 'react-dom'
import renderWithParams from 'react-render-with-params'

const Yo = React.createClass({
  contextTypes: {
    myContext: PropTypes.string,
  },
  getInitialState() {
    return {
      myState: 'myState',
    }
  },
  render({ myProps }, { myState }, { myContext }) {
    return <div>{myProps} {myState} {myContext}</div>
  },
})

const SuperYo = renderWithParams(Yo)

render(<SuperYo myProps="myProps" />, document.getElementById('app'))

Test

npm test