简体   繁体   English

在Material-UI按钮上为onClick事件调用动作创建者不起作用

[英]Calling action creator for onClick event on a material-ui button doesn't work

When I called an action creator for an onClick event on material ui RaisedButton, I got the following error 当我为材质ui RaisedButton上的onClick事件调用动作创建者时,出现以下错误

Failed prop type: Invalid prop onClick of type object supplied to RaisedButton , expected function . 道具类型失败:提供给RaisedButton object类型prop的无效道具onClick ,预期function

This is the component that I've written 这是我写的组件

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 (
        <div>{this.authButton()}</div>
    );
  }
}

const mapStateToProps = (state) => {
  return { authenticated: state.authenticated };
}

export default connect(mapStateToProps, actions)(App);

How to get rid of this error and make it work? 如何摆脱这个错误并使之发挥作用?

它期望功能,所以尝试这个

onClick={() => { this.props.authenticate(false)}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM