0
I have an React app with the following code in App.js:
import React, {Component} from 'react';
class App extends Component {
constructor(){
super();
this.state = {
firstNumber : 0,
secondNumber : 0,
result : 0
}
this.handleChange = this.handleChange.bind(this);
}
handleChange(event){
const {name,value} = event.target;
this.setState({
[name] : value
});
}
render() {
return (
<div>
<label>
<input
type="text"
placeholder="Choose your first number"
name="firstNumber"
value={this.state.firstNumber}
onChange={this.handleChange}
/>
<br/>
<input
type="text"
placeholder="Choose your second number"
name="secondNumber"
value={this.state.secondNumber}
onChange={this.handleChange}
/>
<br/>
<h1>Result : {this.state.result}</h1>
</label>
<h1>{this.state.firstNumber}</h1>
<h1>{this.state.secondNumber}</h1>
</div>
);
}
}
export default 'App';
E no index.js:
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
serviceWorker.unregister();
I wonder why nothing is displayed when I run mine yarn start
.
Here
export default 'App';
should beexport default App;
, you are trying to export a string and not the variable that is your component– MarceloBoni
how to be your package.json? look start what’s happening there
– Davi Wesley
Your example code working https://stackblitz.com/edit/react-azsnge
– MarceloBoni