0.1.0 • Published 8 years ago

react-render-with-params v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

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
0.1.0

8 years ago