javascript - 失败的 prop 类型 : Invalid prop `onClick` of type `object` supplied to `Button` , 预期 `function`

标签 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 还很陌生。问题是,每当我尝试启动应用程序时,我都会收到此错误:

Failed prop type: Invalid prop onClick of type object supplied to Button, expected function.

我错过了什么?

最佳答案

通过像这样破坏来修复它:

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

关于javascript - 失败的 prop 类型 : Invalid prop `onClick` of type `object` supplied to `Button` , 预期 `function`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54006608/

相关文章:

javascript - 在 React 中使用按钮数组

Redux-form 在 OnSubmit 处理程序中返回 Proxy

javascript - 如何仅使用 Redux 管理 React 表单?没有 redux 形式

javascript - HTML5 Canvas Text Stroke 在 chrome 中产生不需要的重叠,但在 Safari 中工作正常

javascript - else if javascript 中的语句无法显示验证消息

javascript - 如何根据身份验证在我的 Reactjs 应用程序中添加 header

reactjs - 警告 : Failed prop type: The prop `store` is marked as required in `Provider` , 但其值为 `undefined` 。在提供者中

javascript - Rails 默认选择单选按钮

javascript - 在 HTML 页面上嵌入 VLC 插件

javascript - 如何使用 Axios reactjs 获取 303 请求的响应头