Create a simple <Hello ${name}/>
component in React, and then pass the name as props between components.
- React
- Create-react-app
- Create a react app called
hello-react
usingnpx create-react-app hello-react
- Change into the newly created project directory with
cd hello-react
. - Follow the requirements below.
For this exercise, you're going to build a <Hello />
component that renders
some data passed in as props.
Create a file called Hello.js
in the src/
directory.
Using a function, define a component called Hello
that renders an h1
with
the text "Hello World"
in it.
Update your <App>
component so that it renders your new Hello
component.
Update your component so that it accepts a name
property. Instead of rendering
"Hello World"
, your Hello
component should now render a message with the
value of name
.
Update your Hello
component in App.js
so that you're passing in a name as
a prop.
Feeling ambitious?
Copy the array below and paste it into your App.js
file above the App
function.
const names = ['Eddie Van Halen', 'Jimi Hendrix', 'Wes Montgomery', 'Frank Zappa', 'John Mayer']
Using the names
array, render a Hello
component for each person in the array.
This is your chance to play with React before we move on to Hooks, use this as a sandbox to nest components, style them as you want (headers, footers, asides), and pass props down as much as you can.
--
Import a font from https://fonts.google.com/.
Take a moment to refamiliarize yourself with the Plagiarism policy. Plagiarized work will not be accepted.
- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact legal@ga.co.