最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - react.js - ReactCSSTransitionGroup throws exception - Stack Overflow

programmeradmin0浏览0评论

I'm trying to add animations for enter into my list inside React.js app (.html).

But ReactCSSTransitionGroup throws such exceptions:

Uncaught TypeError: Cannot read property '_mockedReactClassConstructor' of undefined

together with warnings:

Warning: React.createElement: type should not be null or undefined. It should be a string (for DOM elements) or a ReactClass (for posite ponents). warning.js:36

Warning: Only functions or strings can be mounted as React ponents.

My ponent looks like:

var List = React.createClass({
  render: function () {
    var items = this.props.data
        .filter(function (item) {
            return item.stream;
        })
        .map(function (item) {
            return <div key={item.id}>item.name</div>;
        });

      return (
        <div className="list clearfix">
            <ReactCSSTransitionGroup transitionName="example">
                {items}
            </ReactCSSTransitionGroup>
        </div>
     );
  }
});

I'm trying to add animations for enter into my list inside React.js app (http://facebook.github.io/react/docs/animation.html).

But ReactCSSTransitionGroup throws such exceptions:

Uncaught TypeError: Cannot read property '_mockedReactClassConstructor' of undefined

together with warnings:

Warning: React.createElement: type should not be null or undefined. It should be a string (for DOM elements) or a ReactClass (for posite ponents). warning.js:36

Warning: Only functions or strings can be mounted as React ponents.

My ponent looks like:

var List = React.createClass({
  render: function () {
    var items = this.props.data
        .filter(function (item) {
            return item.stream;
        })
        .map(function (item) {
            return <div key={item.id}>item.name</div>;
        });

      return (
        <div className="list clearfix">
            <ReactCSSTransitionGroup transitionName="example">
                {items}
            </ReactCSSTransitionGroup>
        </div>
     );
  }
});
Share Improve this question edited Jan 13, 2015 at 10:11 Kosmetika asked Jan 13, 2015 at 9:29 KosmetikaKosmetika 21.3k38 gold badges112 silver badges177 bronze badges 2
  • Could you please provide more data? Can you create a test-case on jsfiddle? – Johannes Lumpe Commented Jan 13, 2015 at 10:22
  • this one - jsfiddle/r98d348f/3 works fine until you'll wrap {items} into ReactCSSTransitionGroup.. – Kosmetika Commented Jan 13, 2015 at 10:34
Add a ment  | 

1 Answer 1

Reset to default 8

Since the original answer was based on the assumption that the above code was correct, here the revised one, based on your fiddle.

In your fiddle you do not propery reference the ReactCSSTransitionGroup. You reference it as React.ReactCSSTransitionGroup, which of course is undefined. This is why your fiddle will plain, if you try to wrap anything in it, because you are using an undefined value. To get your fiddle working, you will have to reference the css transition group like this:

var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;

The corrected fiddle: http://jsfiddle/r98d348f/4/

发布评论

评论列表(0)

  1. 暂无评论