react-stateless

0.2.2 • Public • Published

react-stateless

Helpers to write stateless functional components in React.

Write stateless functional components in React with lifecycle methods as pure functions!

ReactStateless.createClass(specification)

specification can be a stateless render function or an object containing pure stateless lifecycle functions.

Example: component as a function

import { React } from 'react';
import { createClass } from 'react-stateless';
 
function ComponentA(props) {
    return <div>{ props.name }</div>;
}
 
// React 0.14
export default ComponentA
// Or
export default createClass(ComponentA);

Example: component as an object

import { React } from 'react';
import { createClass } from 'react-stateless';
 
function shouldComponentUpdate(props, nextProps) {
    return props.name !== nextProps.name;
}
 
function render(props) {
    return <div>{ props.name }</div>;
}
 
export default createClass({shouldComponentUpdate, render})

Supported properties

  • propTypes
  • defaultProps
  • displayName (automatically detected by if your component function or render function is named)

Supported methods

  • componentWillMount(props)
  • componentDidMount(props, refs)
  • componentWillReceiveProps(props, nextProps, refs)
  • shouldComponentUpdate(props, nextProps, refs)
  • componentWillUpdate(props, nextProps, refs)
  • componentDidUpdate(props, prevProps, refs)
  • componentWillUnmount(props, refs)

Readme

Keywords

Package Sidebar

Install

npm i react-stateless

Weekly Downloads

1

Version

0.2.2

License

MIT

Last publish

Collaborators

  • troch