admin管理员组文章数量:1424970
How do I interpret the following error?
TypeError: Cannot read property 'style' of undefined
import React from 'react';
import PropTypes from 'prop-types';
import {VelocityComponent} from 'velocity-react';
import 'velocity-animate/velocity.ui';
const FuseAnimate = (props) => {
const children = React.cloneElement(props.children, {
style: { // this line throws the error
...props.children.style,
visibility: 'hidden'
}
});
return (
<VelocityComponent {...props} children={children}/>
)
};
FuseAnimate.propTypes = {
children: PropTypes.element.isRequired
};
FuseAnimate.defaultProps = {
animation : 'transition.fadeIn',
runOnMount : true,
targetQuerySelector: null,
interruptBehavior : 'stop',
visibility : 'visible',
duration : 300,
delay : 50,
easing : [0.4, 0.0, 0.2, 1],
display : null
};
export default FuseAnimate;
How do I interpret the following error?
TypeError: Cannot read property 'style' of undefined
import React from 'react';
import PropTypes from 'prop-types';
import {VelocityComponent} from 'velocity-react';
import 'velocity-animate/velocity.ui';
const FuseAnimate = (props) => {
const children = React.cloneElement(props.children, {
style: { // this line throws the error
...props.children.style,
visibility: 'hidden'
}
});
return (
<VelocityComponent {...props} children={children}/>
)
};
FuseAnimate.propTypes = {
children: PropTypes.element.isRequired
};
FuseAnimate.defaultProps = {
animation : 'transition.fadeIn',
runOnMount : true,
targetQuerySelector: null,
interruptBehavior : 'stop',
visibility : 'visible',
duration : 300,
delay : 50,
easing : [0.4, 0.0, 0.2, 1],
display : null
};
export default FuseAnimate;
Share
Improve this question
edited Nov 4, 2018 at 8:02
Let Me Tink About It
asked Nov 3, 2018 at 20:38
Let Me Tink About ItLet Me Tink About It
16.2k21 gold badges108 silver badges218 bronze badges
1 Answer
Reset to default 4I believe ...props.children.style
is the source of your error. If you're doing something like...
render() {
<FuseAnimate /> // no children
}
then props.children
will be undefined.
本文标签: javascriptReactjs TypeError Cannot read property 39style39 of undefinedStack Overflow
版权声明:本文标题:javascript - Reactjs TypeError: Cannot read property 'style' of undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745439836a2658396.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论