失败丙类型:无效丙型`object`供给到`Button`的`onClick`,预期`functio

2019-10-31 07:50发布

这是我的代码:

我的容器:

import {connect} from 'react-redux';
import UI from '../../ui/studentRegistrationUI/RegisterFormUI'
import {beginRegistration, setLevel} from "../../../../actions";

const mapStateToProps = state => ({user: state.user});
const mapDispatchToProps = dispatch => ({
    handleClick() {
        dispatch(beginRegistration('student'));
    }
});

export default connect(mapStateToProps, mapDispatchToProps)(UI)

我UI组件:

//imports
export default (handleClick = f => f) => (
    <div className="table_bg">
        <div className="container">
            <div className="row">
                <Button className='custom_register_button'
                        onClick={handleClick}>
                </Button>
            </div>
        </div>
    </div>
);

现在我想创建一个调度员,并将其发送到UI一个按钮被点击时调用。 我还是新的终极版。 问题是,我得到这个错误,每当我尝试启动应用程序:

失败丙类型:无效托onClick类型的object提供给Button ,预期function

我在想什么?

Answer 1:

Fixed it by destructing like so:

export default ({handleClick = f => f}) => (


文章来源: Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function`