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

This is my code:My container:import {connect} from 'react-redux';import UI from '....

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}) => (

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745444857a4628000.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信