道具类型失败:提供给“按钮”的对象类型为“对象”的道具“ on​​Click”无效,预期功能“

时间:2019-01-02 12:42:46

标签: javascript reactjs redux react-redux

这是我的代码:

我的容器:

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。我还是Redux的新手。问题是,每当我尝试启动该应用程序时,都会出现此错误:

  

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

我想念什么?

1 个答案:

答案 0 :(得分:1)

通过破坏来修复它:

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