https://github.com/troch/react-stateless
Helpers to write stateless components in React
https://github.com/troch/react-stateless
Last synced: about 1 year ago
JSON representation
Helpers to write stateless components in React
- Host: GitHub
- URL: https://github.com/troch/react-stateless
- Owner: troch
- License: mit
- Created: 2015-10-08T19:00:30.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-10-24T20:49:24.000Z (over 9 years ago)
- Last Synced: 2025-05-29T20:16:58.458Z (about 1 year ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 48
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](https://facebook.github.io/react/blog/2015/10/07/react-v0.14.html#stateless-functional-components)__
or an __object containing pure stateless lifecycle functions__.
#### Example: component as a function
```javascript
import { React } from 'react';
import { createClass } from 'react-stateless';
function ComponentA(props) {
return
{ props.name };
}
// React 0.14
export default ComponentA
// Or
export default createClass(ComponentA);
```
#### Example: component as an object
```javascript
import { React } from 'react';
import { createClass } from 'react-stateless';
function shouldComponentUpdate(props, nextProps) {
return props.name !== nextProps.name;
}
function render(props) {
return
{ props.name };
}
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)`