Calling action creator for onClick event on a material-ui button doesn't work
当我为材质ui RaisedButton上的onClick事件调用动作创建者时,出现以下错误
失败的道具类型:提供给
这是我编写的组件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import React, { Component } from 'react'; import RaisedButton from 'material-ui/RaisedButton'; import { connect } from 'react-redux'; import * as actions from '../actions'; class App extends Component { authButton = () => { if(this.props.authenticated) { return <RaisedButton label="Sign out" onClick={this.props.authenticate(false)} /> } return <RaisedButton label="Sign out" onClick={this.props.authenticate(true)} /> } render() { return ( {this.authButton()} ); } } const mapStateToProps = (state) => { return { authenticated: state.authenticated }; } export default connect(mapStateToProps, actions)(App); |
如何消除此错误并使其正常工作?
它需要一个功能,所以尝试这个