最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Failed prop type: Invalid prop `onClick` of type `object` supplied to `Button`, expected `function` - Stack Overflo

programmeradmin1浏览0评论

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 ponent:

//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?

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 ponent:

//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?

Share Improve this question asked Jan 2, 2019 at 12:42 Alex IronsideAlex Ironside 5,07914 gold badges76 silver badges135 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Fixed it by destructing like so:

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论