How to use the createClass function from react

Find comprehensive JavaScript react.createClass code examples handpicked from public code repositorys.

160
161
162
163
164
165
166
167
168
169
var React = require('react');

var model = new Backbone.Model({
  helloWorld: 'Hello world!'
});
var HelloWorld = React.createClass({
  mixins: [backboneMixin],
  render: function () {
    return React.DOM.div({}, this.state.model.helloWorld);
  }
fork icon73
star icon815
watch icon23

+ 7 other calls in file

80
81
82
83
84
85
86
87
88
89
var assetpath = function(filename) { return '../assets/' + filename; };

var Sprite = React.createFactory(ReactPIXI.Sprite);
var DisplayObjectContainer = React.createFactory(ReactPIXI.DisplayObjectContainer);

var CupcakeComponent = React.createClass({
  displayName: 'CupcakeComponent',
  // maps from cupcake toppings to the appropriate sprite
  spritemapping : {
    'vanilla' : assetpath('creamVanilla.png'),
fork icon73
star icon741
watch icon27

+ 3 other calls in file

141
142
143
144
145
146
147
148
149
150
var React = require('react')
var render = require('react-dom').render
var hyperx = require('hyperx')
var hx = hyperx(React.createElement)

var App = React.createClass({
  getInitialState: function () { return { n: 0 } },
  render: function () {
    return hx`<div>
      <h1>clicked ${this.state.n} times</h1>
fork icon71
star icon997
watch icon18

+ 3 other calls in file

28
29
30
31
32
33
34
35
36
  }
  return children;
};


var ParallaxScrollViewComposition = React.createClass({
  propTypes: {
    scrollViewComponent: React.PropTypes.func,
  },
fork icon82
star icon578
watch icon15

0
1
2
3
4
5
6
7
8
9
/** @jsx React.DOM */
var React = require('react');
var _ = require('underscore');
var UI = require('react-topui');

module.exports = React.createClass({
  
  propTypes: {
    links: React.PropTypes.array.isRequired
  },
fork icon42
star icon260
watch icon20

+ 3 other calls in file

2
3
4
5
6
7
8
9
10
11
var React = require('react');
var classNames = require('classnames');
var omit = require('object.omit');
var ClassNameMixin = require('./mixins/ClassNameMixin');

var Progress = React.createClass({
  mixins: [ClassNameMixin],

  propTypes: {
    classPrefix: React.PropTypes.string,
fork icon235
star icon0
watch icon92

10
11
12
13
14
15
16
17
18
19
var Events = require('./utils/Events');
var isNodeInTree = require('./utils/isNodeInTree');
var createChainedFunction = require('./utils/createChainedFunction');
var canUseDOM = require('./utils/canUseDOM');

var Dropdown = React.createClass({
  mixins: [ClassNameMixin],

  propTypes: {
    title: React.PropTypes.node.isRequired,
fork icon235
star icon0
watch icon2

+ 3 other calls in file

10
11
12
13
14
15
16
17
18
19

var Column = FixedDataTable.Column;
var Link = Router.Link;
var Table = FixedDataTable.Table;

var Tracks = (exports.Tracks = React.createClass({
        mixins: [Reflux.listenTo(Stores.active, 'setActive')],
        getDefaultProps: function() {
                return {
                        tracks: [],
fork icon26
star icon365
watch icon19

+ 7 other calls in file

23
24
25
26
27
28
29
30
31
32
```
var React = require('react');
var ReactDOM = require('react-dom');

// 定义组件
var HelloMessage = React.createClass({
  render: function() {
    return <div> React,我们来了... </div>;
  }
});
fork icon59
star icon153
watch icon12

372
373
374
375
376
377
378
379
380
381

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

var React = require('react'); // var AptList = React.createClass({


var AptList = /*#__PURE__*/function (_React$Component) {
  _inherits(AptList, _React$Component);
fork icon10
star icon22
watch icon4

0
1
2
3
4
5
6
7
8
9
var _ = require('lodash')
var React = require('react')
var TriangleDown = require('./SVGCollection').TriangleDown
var color = require('../../js/color')

var GeneOpenMenu = React.createClass({

    propTypes: {
        gene: React.PropTypes.object
    },
fork icon6
star icon2
watch icon25

+ 4 other calls in file

1
2
3
4
5
6
7
8
9
10
var React = require('react')
var GeneOpenMenu = require('../ReactComponents/GeneOpenMenu')
var SVGCollection = require('../ReactComponents/SVGCollection')
var color = require('../../js/color')

var GenePanel = React.createClass({
    
    propTypes: {
        gene: React.PropTypes.object.isRequired
    },
fork icon6
star icon2
watch icon25

+ 3 other calls in file

58
59
60
61
62
63
64
65
66
67
结果发现大家真正需要的就是 DOM 节点本身,封装了半天完全是浪费感情。

于是在 v0.14 版中 refs 指向的就是 DOM 节点,同时也会保留 `.getDOMNode()` 方法(带 warning),最终在 v0.15 版中去除该方法。

```javascript
var Zoo = React.createClass({
  render: function() {
    return <div>Giraffe name: <input ref="giraffe" /></div>;
  },
  showName: function() {
fork icon2
star icon23
watch icon13

+ 3 other calls in file

7
8
9
10
11
12
13
14
15
16
17
18
19
    styler = require('react-styler'),
    Icon = require('./Icon'),
    Button = require('./Button'),
    Input = require('./Input');


var FileUploader = React.createClass({


    displayName: 'FileUploader',


    propTypes: {
fork icon1
star icon5
watch icon15

25
26
27
28
29
30
31
32
33
34
35
36
37
        slider: require('react-color/lib/components/slider/Slider'),
        swatches: require('react-color/lib/components/swatches/Swatches')
    };
})();


var ColorPicker = React.createClass({


    displayName: 'ColorPicker',


    propTypes: {
fork icon1
star icon5
watch icon15

6
7
8
9
10
11
12
13
14
15
16
17
18
    numeral = require('numeral'),
    DropDownContent = require('./DropDownContent'),
    ScrollableContent = require('./ScrollableContent'),
    styler = require('react-styler');


var ChartLegend = React.createClass({


    displayName: 'ChartLegend',


    propTypes: {
fork icon1
star icon5
watch icon15

9
10
11
12
13
14
15
16
17
18
19
20
21
    _ = require('lodash'),
    styler = require('react-styler'),
    stringToBoolean = require('../helpers/stringToBoolean'),
    icons = require('../icons');


var CheckBox = React.createClass({


    displayName: 'CheckBox',


    mixins: [styler.mixinFor('CheckBox')],
fork icon1
star icon5
watch icon15

3
4
5
6
7
8
9
10
11
12
13
14
15
    ReactDOM = require('react-dom'),
    _ = require('lodash'),
    Icon = require('./Icon'),
    styler = require('react-styler');


var Input = React.createClass({


    displayName: 'Input',


    /**
fork icon1
star icon5
watch icon15

144
145
146
147
148
149
150
151
152
153
154
155
    clearTimeout(this.timeoutID);
    this.timeoutID = setTimeout.apply(null, arguments);
  }
};


const ReactPlayground = React.createClass({
  mixins: [selfCleaningTimeout],


  propTypes: {
    codeText: React.PropTypes.string.isRequired,
fork icon0
star icon1
watch icon0

1
2
3
4
5
6
7
8
9
10
11
var WeatherForm = require('WeatherForm');
var WeatherMessage = require('WeatherMessage');
var ErrorModal = require('ErrorModal');
var openWeatherMap = require('openWeatherMap');


var Weather = React.createClass({
  getInitialState: function () {
    return {
      isLoading: false
    }
fork icon0
star icon0
watch icon1