我如何解释以下错误?
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;
最佳答案
我相信 ...props.children.style
是您错误的根源。如果你正在做类似...
render() {
<FuseAnimate /> // no children
}
那么
props.children
将是未定义的。关于javascript - Reactjs 类型错误 : Cannot read property 'style' of undefined,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53135296/