失败的道具类型:提供给“按钮"的“对象"类型的无效道具“onClick",预期为“功能" [英] Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function`

查看:65
本文介绍了失败的道具类型:提供给“按钮"的“对象"类型的无效道具“onClick",预期为“功能"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

我的容器:

import {connect} from 'react-redux';从../../ui/studentRegistrationUI/RegisterFormUI"导入 UI从../../../../actions"导入 {beginRegistration, setLevel};const mapStateToProps = state =>({用户: state.user});const mapDispatchToProps = dispatch =>({句柄点击(){dispatch(beginRegistration('student'));}});导出默认连接(mapStateToProps,mapDispatchToProps)(UI)

我的 UI 组件:

//导入导出默认值(handleClick = f => f)=>(<div className="table_bg"><div className="容器"><div className="row"><Button className='custom_register_button'onClick={handleClick}></按钮>

);

现在我正在尝试创建一个调度程序并将其发送到用户界面以在单击按钮时调用.我还是 Redux 的新手.问题是,每当我尝试启动应用程序时,我都会收到此错误:

<块引用>

失败的道具类型:提供给Buttonobject类型的无效道具onClick,预期function.>

我错过了什么?

解决方案

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

导出默认值 ({handleClick = f => f}) =>(

This is my code:

My container:

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)

My UI component:

//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>
);

Right now I am trying to create a dispatcher and send it to the UI to be called when a button is clicked. I am still new to Redux. The problem is, I am getting this error, whenever I try to launch the app:

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

What am I missing?

解决方案

Fixed it by destructing like so:

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

这篇关于失败的道具类型:提供给“按钮"的“对象"类型的无效道具“onClick",预期为“功能"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆