[英]How to import ReactCSSTransitionGroup using es6 syntax?
I'm trying to create Modal window to my React app, and I'm following this tutorial. 我正在尝试为我的React应用程序创建Modal窗口,并且正在关注本教程。
However, I got the following error 但是,出现以下错误
Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of `Modal`.
here is my code 这是我的代码
import React from 'react'
import {ReactCSSTransitionGroup} from 'react-addons-css-transition-group'
const Modal = React.createClass ({
render() {
if (this.props.isOpen) {
return (
<ReactCSSTransitionGroup transitionName={this.props.transitionName}>
<div className="modal">
{this.props.children}
</div>
</ReactCSSTransitionGroup>
)
}
else {
return (
<ReactCSSTransitionGroup transitionName={this.props.transitionName} />
)
}
}
})
module.exports = Modal
I installed react-addons-css-transition-group by npm install --save react-addons-css-transition-group
我通过npm install --save react-addons-css-transition-group
The problem is clearly ReactCSSTransitionGroup not being imported right, as replacing it with plain div doesn't throw any errors. 问题显然是ReactCSSTransitionGroup没有正确导入,因为用plain div替换它不会引发任何错误。
You have to remove the braces from {ReactCSSTransitionGroup}
您必须从{ReactCSSTransitionGroup}
删除括号
import {ReactCSSTransitionGroup} from 'react-addons-css-transition-group'
should be 应该
import ReactCSSTransitionGroup from 'react-addons-css-transition-group'
Also, you should provide a key for the children inside ReactCSSTransitionGroup
另外,您还应该为ReactCSSTransitionGroup
的子项提供一个密钥
<ReactCSSTransitionGroup transitionName={this.props.transitionName}>
<div className="modal" key="transitionGroup">
{this.props.children}
</div>
</ReactCSSTransitionGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.