Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from "react";
  2.  
  3. class Recipe extends Component {
  4.   constructor(props) {
  5.     super(props);
  6.  
  7.     this.state = {
  8.       // See App.js for more details. loadRecipe is defined there.
  9.       recipe: this.props.loadRecipe(this.props.id)
  10.     };
  11.   }
  12.  
  13.   render() {
  14.     // In case the Recipe does not exists, let's make it default.
  15.     let title = "Recipe not found";
  16.  
  17.     // If the recipe *does* exists, make a copy of title to the variable.
  18.     if (this.state.recipe) {
  19.       title = this.state.recipe.title;
  20.     }
  21.  
  22.     return (
  23.       <React.Fragment>
  24.         <h1>The recipe:</h1>
  25.         <p>{title}</p>
  26.         {/* TODO: Print the rest of the recipe data here */}
  27.       </React.Fragment>
  28.     );
  29.   }
  30. }
  31.  
  32. export default Recipe;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement