class AddDesk extends React.Component {
constructor() {
super();
this.state = {showForm: false};
this.input = React.createRef();
}
handleShowForm() {
this.setState({
showForm: true
});
console.log(this.input);
}
handleHideForm() {
this.setState({
showForm: false
});
}
render() {
let deskAddRender;
{
if ( !this.state.showForm ) {
deskAddRender = (
<button onClick={ this.handleShowForm.bind(this) }>Добавить еще одну колонку</button>
);
} else {
deskAddRender = (
<div className="desk__add_form">
<input type="text" className="title_active" placeholder="Введите заголовок списка" maxLength="512" ref={ (node) => this.input = node }/>
<button className="green_btn">Добавить список</button>
<button className="cancel_btn" onClick={ this.handleHideForm.bind(this) }><img src="img/icons/close.svg" alt="Отмена" /></button>
</div>
);
}
}
return (
<div className="desk__add">
{ deskAddRender }
</div>
);
}
}
ref={ this.input }
this.setState({
showForm: true
}, () => {
console.log(this.input);
});