这是我的代码:
我的容器:
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 还很陌生。问题是,每当我尝试启动应用程序时,我都会收到此错误:
失败的道具类型:提供给
的onClick
类型的无效道具object
,预期为Button
。function
我错过了什么?
通过像这样破坏来修复它:
export default ({handleClick = f => f}) => (
在使用 React.JS 时,使用 onClick() 会出现错误:
<Button type="button" onClick={rodarFuncao(parametro)}>
Excluir
</Button>
Só que de vez de fazer do jeito quemostrei você tem que passar () =>,例如:
<Button type="button" onClick={() => rodarFuncao(parametro)}> // Jeito certo
Excluir
</Button>