Skip to content

obipawan/react-decorator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Decorators

An assortment of useful @decorators for react and react-native

Warning! - If you're using babel 6, you'll have to use babel-plugin-transform-decorators-legacy plugin [Follow thread]. If you're using babel 5, you're good to go.

installation

npm i -S react-decorator

Usage

Request

import React, { Component } from 'react'
import { request } from 'react-decorator'

@request({
	task: fetch(url),
	LoadingComponent: () => <div>loading....</div>,
	ErrorComponent: ({ error }) => <div>{ error }</div>,
})
class App extends Component {
	render() {
		return <div> content </div>
	}
}

Measure

import React, { Component } from 'react'
import { measure } from 'react-decorator'

@measure()
class App extends Component {
	render () {
		return (
			<div>
				This text fits inside a
				{ this.props.width }x{ this.props.height }
				box
			</div>
		)
	}
}

More coming soon...