我正在尝试使用一个简单的"抽屉"组件来测试React的TransitionGroups.我到目前为止以及JSBin上的内容.如果您尝试运行它,它可以工作,但我收到错误:
未捕获的TypeError:无法读取未定义的属性"componentWillLeave"
我在这做错了什么?
var DrawerInner = React.createClass({ componentWillEnter: function(cb) { var $el = $(this.getDOMNode()); var height = $el[0].scrollHeight; $el.stop(true).height(0).animate({height:height}, 200, cb); }, componentWillLeave: function(cb) { var $el = $(this.getDOMNode()); $el.stop(true).animate({height:0}, 200, cb); }, render: function() { return{this.props.children}; } }); var Drawer = React.createClass({ getInitialState: function() { return { open: false }; }, componentWillMount: function() { this.setState({ open: this.props.open }); }, componentWillReceiveProps: function(props) { this.setState({ open: props.open }); }, open: function() { this.setState({ open: true }); }, close: function() { this.setState({ open: false }); }, toggle: function() { this.setState({ open: !this.state.open }); }, render: function() { return ({this.state.open && ); } });{this.props.children} }
Sophie Alper.. 5
看起来这是ReactTransitionGroup中的一个错误.我刚刚提出了一个修正案:
https://github.com/facebook/react/pull/1492