- Practice passing props from parent components to children
- Practice using default props
- Practice jumping into and improving existing code
This is a barebones React application used to showcase the nine greatest movies of all time. Your job is to update it so that it passes props from parent to children components correctly. In addition, you will implement default props so that 'bad/missing data' is properly handled - preventing our user interface from blowing up our visitors' computers
Following is the component tree. When fully rendered, there are 9
MovieCards
rendered by MovieShowcase
:
└── MovieShowcase
│
├── MovieCard
│ ├── CardFront
│ └── CardBack
│
└── MovieCard
├── CardFront
└── CardBack
MovieShowcase
is the component that will house all of the 'raw' data
associated with the movies we want to display. This data is located in
src/data.js
and is already being imported.
MovieCard
components (which showcase a single movie) receive their individual
movie information from MovieShowcase
as four props: title
, IMDBRating
,
genres
, and poster
. Following, the props are passed again to either
CardFront
or CardBack
.
In our movie data set, we occasionally have missing data. This is where
defaultProps
come in and really pull our buns out of the fire. We will be
handling all of our defaultProp
'ing in MovieCard
before they are passed down
the chain to the front and back components.
.map
over the imported movie data array and renderMovieCard
s for each element. (see documentation)- Don't forget to pass all 4 props
defaultProps
should be assigned inMovieCard
for all four of the props:
title
receives an 'Unknown' stringIMDBRating
simply gets assigned to nullgenres
should receive a value that will work with ourCardBack
component's rendering method for genres. The screen should read: 'No Genre(s) Found'poster
should get the stringdefault
- pass the correct props to the correct back/front components
(Note: the
posterMap
already takes care of converting a string into the appropriate poster asset)
- the prop should be used to apply a background image. This can be done inline via:
style={{backgroundImage: `url(${prop})`}}
- render the genres (as comma separated) strings
- render the title value
- Finish writing the method
generateRatingElement
, which should do the following:
- if the IMDBRating prop is null, return an
<h4>
with the contents 'No Rating Found' - otherwise, return
<img src={imgMapper[prop]} alt="" />
(using the correct prop)
npm start
and make sure everything is functioning how you would like!
View Props Lab on Learn.co and start learning to code for free.