项目作者: obipawan

项目描述 :
An assortment of @decorators for react and react-native
高级语言: JavaScript
项目地址: git://github.com/obipawan/react-decorator.git
创建时间: 2017-04-02T15:46:41Z
项目社区:https://github.com/obipawan/react-decorator

开源协议:

下载


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

  1. npm i -S react-decorator

Usage

Request

  1. import React, { Component } from 'react'
  2. import { request } from 'react-decorator'
  3. @request({
  4. task: fetch(url),
  5. LoadingComponent: () => <div>loading....</div>,
  6. ErrorComponent: ({ error }) => <div>{ error }</div>,
  7. })
  8. class App extends Component {
  9. render() {
  10. return <div> content </div>
  11. }
  12. }

Measure

  1. import React, { Component } from 'react'
  2. import { measure } from 'react-decorator'
  3. @measure()
  4. class App extends Component {
  5. render () {
  6. return (
  7. <div>
  8. This text fits inside a
  9. { this.props.width }x{ this.props.height }
  10. box
  11. </div>
  12. )
  13. }
  14. }

More coming soon…