【问题标题】:Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function`道具类型失败:提供给“按钮”的“对象”类型的无效道具“onClick”,应为“功能”
【发布时间】:2019-01-02 12:42:46
【问题描述】:

这是我的代码:

我的容器:

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

道具类型失败:提供给Buttonobject类型的无效道具onClick,应为function

我错过了什么?

【问题讨论】:

    标签: javascript reactjs redux react-redux


    【解决方案1】:

    通过破坏来修复它:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      • 2017-12-23
      • 2020-07-23
      • 1970-01-01
      • 2017-12-12
      • 1970-01-01
      相关资源
      最近更新 更多