16. Fetching Data on Initial Render and Refactoring with Hooks
Activity 16.01: Creating an App Using Potter API
Solution:
- Start a new React application for the project named
harry-potter-api
:npx create-react-app harry-potter-api
- In the
src
folder, remove all the existing files. Once they are removed, create a new file calledindex.js
and add the following code. This will import the<App>
component and render it in 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 folder calledcomponents
and then create a file calledApp.js
inside thecomponent
folder. Once that's done, add some boilerplate for the<App>
component:import React from 'react'; const App = () => { Â Â return( Â Â Â Â <div className="page"> Â ...