Skip to content

Instantly share code, notes, and snippets.

@luisjunco
Created June 6, 2024 14:45
Show Gist options
  • Select an option

  • Save luisjunco/4247a167def16bc7aede4bb1f07cb8a5 to your computer and use it in GitHub Desktop.

Select an option

Save luisjunco/4247a167def16bc7aede4bb1f07cb8a5 to your computer and use it in GitHub Desktop.
Exercise - TypeScript + React: components and props

Exercise - TypeScript + React: Components and props

Initial code

Iteration 1: implement the component Movie

  • For this iteration, you will work on Movie.tsx
  • This component expects to receive the following props (hint: you can create a type alias):
    • title (string)
    • rating (number)
    • genres (an array of strings)
    • imageUrl (string)
  • This component should display the info that we receive from props (ie. the title, the rating etc.)
  • Hint: if you get blocked, have a look at this example: https://stackblitz.com/edit/vitejs-vite-ap6thv?file=src%2Fcomponents%2FRecipe.tsx

Iteration 2: render 2 movies

  • For this iteration, you will work on App.tsx
  • In the "App" component, render 2 movies
  • ex: <Movie title="The Godfather" />
  • You will need to pass the correct props

Iteration 3:

  • modify the component Movie so that imageUrl is optional
  • hint: research 'typescript type alias optional properties'

Solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment