7. Communication between Components
Activity 7.01: Creating a Temperature Converter
Solution:
- Run
npx create-react-app temeprature-converter
. - In the
src
folder, create a file calledindex.js
and add the following code. It will import the <App> component and render it in the HTML:import React from 'react'; import ReactDOM from 'react-dom'; import App from './components/App'; ReactDOM.render(<App />, document.querySelector('#root'));
- Still in the src folder, create a
components
folder and inside the components folder, create a new file calledApp.js
. - In the
App.js
file, let's import React andApp.css
. Also, add some boilerplate for the<App>
component:import React, { Component } from 'react'; import './App.css'; class App extends Component { Â Â render() { Â Â Â Â return ( Â Â Â Â Â Â <div className="container"> Â ...