practice assignment

  1. value of newDesserts

    const desserts = [
      {
        title: 'Chocolate Cake',
        description: 'Chocolate cake is a cake flavored with melted chocolate',
        calories: 500,
      }
    ];
    
    const newDesserts = desserts.map((dessert) => {
      return {
        title: dessert.title.toUpperCase(),
        // mapping output merges the previous object values after the title is re-defined, it has no effect and the title is still as before
        ...dessert,
        kCal: dessert.calories / 1000,
      };
    });
    
    // returns
    [
      {
        title: 'Chocolate Cake',
        description: 'Chocolate cake is a cake flavored with melted chocolate',
        calories: 500,
        kCal: 0.5,
      }
    ]
    
  2. how to access dynamic data inside JSX from render function

    wrapping variable in {}

  3. potential problems with using a randomizer function that generates an integer number from 0 to 10 as a key for your list items, having a list of only eight items

  4. react warnings

    // key per list item is missing
    {todos.map((todo, index) => (
      <ToDo id={todo.id} />
    ))}
    
    // keys are the same for all items
    {todos.map((todo, index) => (
      <ToDo key=”myKey” id={todo.id} />
    ))}
    
  5. potential problem with using index as key

    if order of items changes performance and state can be negatively impacted