JSPM

react-mini-this

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 13
  • Score
    100M100P100Q36507F
  • License MIT

React components as pure functions with function bind syntax

Package Exports

  • react-mini-this

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-mini-this) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-mini-this Build Status

Create react components as pure functions with function bind syntax

Install

$ npm install --save react-mini-this

Usage

var React = require('react');
var mini = require('react-mini-this');
var pure = require('react-mini-this/pure');


module.exports = (
    props => <h1>Title: {props.title}</h1> 
)::mini();

module.exports = (
    props => <h1>Title: {props.title}</h1> 
)::pure();

with props and state

function Counter ( ({ step = 1 } , { setState, state: { count } }) { 
    var incCounter = () => setState({ count : count + step });

  return <span>Counter: {count}<button onClick={incCounter}>+1</button></span> 
}::mini( { count: 10 });

React.render(
  <Counter step={10}/>,
  document.body
)

API

(render:Function(props, component))::mini([initialState:Object])

  • render : This is the actual render function.
    • props:Object : The props of the component
    • component:Object : The component (this)
  • initialState : The initial state of the component.

:: huh?

If you’re wondering what the :: thing means, you’d better read this excellent overview by @jussi-kalliokoski or have a look at the function bind syntax proposal.

License

MIT © Christoph Hermann