const preact = require('preact'); const { Component } = require('preact'); class SpawnButton extends Component { constructor(props) { super(props); this.state = { value: null, enabled: false }; this.handleInput = this.handleInput.bind(this); this.handleSubmit = this.handleSubmit.bind(this); this.enable = this.enable.bind(this); } handleInput(event) { console.log(event.target.value); this.setState({ value: event.target.value }); } handleSubmit(event) { event.preventDefault(); this.props.spawn(this.state.value); this.setState({ value: null, enabled: false }); } enable() { this.setState({ enabled: !this.state.enabled }); } render() { const selected = this.state.enabled ? 'selected' : ''; return (
); } } module.exports = SpawnButton;