Coding task · JavaScript and React course · Module 15: Patterns and Architecture

Practice: Slot Pattern and Component Injection

A slot is an ordinary prop holding a JSX element, and the condition slot && <wrapper> does not render an empty frame when the slot is missing. The syntax { as: Component = 'button' } renames the as prop to Component (a capital letter, because JSX treats lowercase names as HTML tags) and sets a default value. The rest operator ...props collects all the remaining props, and the spread {...props} hands them to the element. In Component Injection the list draws nothing itself: each list item comes from the result of the consumer's function.

Task

Finish three components that hand control to the consumer. SpaceCard (Slot Pattern): ___BLANK1___ and ___BLANK2___ are the conditions that make <header> and <footer> appear only when the consumer passed the header or footer prop (just like actions already works). SpaceButton (polymorphic): ___BLANK3___ is the name we rename the as prop to so that we can use it in JSX as an element, and ___BLANK4___ passes the remaining props (onClick, href, to) to the element. MissionList (Component Injection): ___BLANK5___ is the element shown instead of an empty list (when it is not given, the default message stays), and ___BLANK6___ calls the renderItem function with the mission and its index.