3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

React.PropTypesをDecoratorsを使って書けるライブラリを書いた

Posted at

ES6 classを使ってReactのComponentを書こうとすると、PropTypesを定義するのにコンストラクタのプロパティにしろとか、Property Initializersを使えとか言われているけど( https://facebook.github.io/react/blog/2015/01/27/react-v0.13.0-beta-1.html )、どうもしっくりこないのでDecoratorを使って定義できるライブラリを書きました。
https://github.com/popkirby/react-props-decorators

コード例

import React from 'react';
import { propTypes, defaultProps } from 'react-props-decorators';

@propTypes({
  foo: React.PropTypes.string,
  bar: React.PropTypes.number
})
@defaultProps({
  foo: "defaultString",
  bar: 100
})
class Baz extends React.Component {
  /* ... */
}

もともとのpropTypesなどの中身をDecoratorに持ってくるだけです。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?