Reactjs类型错误:无法读取未定义的“style”属性。

3
我该如何解读以下错误信息?
类型错误:无法读取未定义对象的'style'属性。
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;
1个回答

4
我认为...props.children.style是您错误的来源。 如果您正在执行类似以下操作的操作...
render() {
  <FuseAnimate /> // no children
}

那么props.children将会是未定义的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接