我是React的新手,我想在点击后隐藏一个按钮。下面的两个代码段下面是proptypes。我需要一个hideSubmit按钮吗?单击后如何隐藏按钮?我读到我可以通过州或CSS来做到这一点。既然这是一个按钮,它似乎更容易使用CSS?任何帮助将不胜感激。
答案 0 :(得分:-1)
/* eslint-disable jsx-a11y/img-has-alt,class-methods-use-this */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import todoStyle from 'src/style/todo-style.scss';
import { Router, Route, hashHistory as history } from 'react-router';
import Myaccount from 'src/components/myaccount.jsx';
export default class Headermenu extends Component {
constructor(){
super();
// Initial state
this.state = { open: false };
}
toggle() {
this.setState({
open: !this.state.open
});
}
componentdidMount() {
this.menuclickevent = this.menuclickevent.bind(this);
this.collapse = this.collapse.bind(this);
this.myaccount = this.myaccount.bind(this);
this.logout = this.logout.bind(this);
}
render() {
return (
<div>
<div style={{ textAlign: 'center', marginTop: '10px' }} id="menudiv" onBlur={this.collapse}>
<button onClick={this.toggle.bind(this)} > Menu </button>
<div id="demo" className={"collapse" + (this.state.open ? ' in' : '')}>
<label className="menu_items" onClick={this.myaccount}>MyAccount</label>
<div onClick={this.logout}>
Logout
</div>
</div>
</div>
</div>
);
}
menuclickevent() {
const listmenu = document.getElementById('listmenu');
listmenu.style.display = 'block';
}
logout() {
console.log('Logout');
}
myaccount() {
history.push('/myaccount');
window.location.reload();
}
}
enter code here