javascript - Reactjs TypeError: Cannot read property 'style' of undefined - Stack Overflow

How do I interpret the following error?TypeError: Cannot read property 'style' of undefinedim

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
Add a ment  | 

1 Answer 1

Reset to default 4

I 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745439836a4627780.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信