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
srcfolder, remove all the existing files. Once they are removed, create a new file calledindex.jsand 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
srcfolder, create a folder calledcomponentsand then create a file calledApp.jsinside thecomponentfolder. Once that's done, add some boilerplate for the<App>component:import React from 'react'; const App = () => { Â Â return( Â Â Â Â <div className="page"> Â ...