Failed prop type: Invalid prop `onClick` of type `

2019-08-16 20:33发布

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?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-16 21:03

Fixed it by destructing like so:

export default ({handleClick = f => f}) => (
查看更多
登录 后发表回答