Why can’t type in the input field?
I have a problem like this:
import React, { Component } from 'react';
import Operations from './operations.json';
import Variables from './variables.json';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
operations: Operations,
variables: Variables,
ex:[]
};
}
handleClick(element) {
console.log(element);
let newArr=[...this.state.ex];
newArr.push(element);
this.setState({ex: newArr});
console.log(this.state.ex);
}
handleChange(event) {
let newArr=[...this.state.ex];
newArr.push(event.target.value);
this.setState({ex:newState});
if(typeof(event.target.value) === 'number'){
let newArr=[...this.state.ex];
newArr.push(event.target.value);
this.setState({ex:newArr});
}
else{
event.target.value:null
}
}
render () {
return (
<div className={"parent"}>
{
Object.keys(this.state.operations).map(key => {
return <button onClick={this.handleClick.bind(this,this.state.operations[key])} className={"button"}> {key} {this.state.operations[key]}</button>
})
}
<br/>
{
Object.keys(this.state.variables).map(key => {
return <button onClick={this.handleClick.bind(this,this.state.variables[key])} className={"button"}> {key} {this.state.variables[key]}</button>
})
}
<br/>
<input onChange={this.handleChange.bind(this)} value={this.state.ex}/>
</div>
)
}
}
export default App;