Giter VIP home page Giter VIP logo

crud-lab's Introduction

Create and Delete Lab

Objectives

  • Implement a Yelp-like application where users can create and delete both restaurants and reviews of each restaurant.

Introduction

In this lab, we will practice creating and removing various items using Redux. We are working with two different resources, with each restaurant having many reviews and reviews belonging to a restaurant. Similar to the previous Redux delete lab, implement container components to connect to your Redux store - one for restaurants and one for reviews.

Hint: Container components can be nested as children in the same way as any other component, even if they aren't actually displaying any visual content.

Instructions

  1. Start off by working on the components for displaying restaurants. First, you'll need to create a RestaurantsContainer component that will connect to Redux and pass the appropriate props down to its children. Then you will need a RestaurantInput component that allows a user to create new restaurants. You will then want to create a Restaurants component that displays a list of restaurants, and a Restaurant component which is responsible for each restaurant (and contains the button to delete). Users should also be able to delete restaurants. To implement this, you will need to give each restaurant an ID.

Note: To implement IDs, it may be worth integrating another library in the reducer called cuid. You can see that we already imported it in the reducer file for you. The library will generate a unique id for you:

import cuid from 'cuid';

console.log(cuid());
// ch72gsb320000udocl363eofy

For simplicity with testing, restaurant data stored in Redux should have text and id keys.

  1. You will also need to create a reviews resource. Similar to the components for Restaurant, users should be able to create a review that is specifically associated with the related restaurant, and those reviews should be displayed underneath the related restaurant. Because reviews are associated to specific restaurants, the ReviewsContainer should be nested within the Restaurant component. Users should also be able to delete a specific review.

Note: When building your input forms, only use basic input elements for this lab's tests.

Since you'll need to be able to associate reviews to restaurants, and delete specific reviews, reviews stored in Redux should have a text key for the review content, a restaurantId key to associate and display the review with a specific restaurant and an id key unique to the review itself.

Conclusion

Once all tests are passing, you'll be able to create and delete restaurants and their specific reviews. Take note of the structure of this app - containers can end up anywhere in an app, even nested way down the component tree. This set up can feel a bit counterintuitive initially since we could have a presentational component that has a container component as a child, but the benefit is that none of the non-container components have any code related to Redux! They're just firing props!

Bonus: So, we're now able to Create, Read and Delete in Redux. You have learned all you need to know to complete what is required to Update an item. Think about how this would be done. You would want to probably include an additional button with each restaurant and review that, when clicked, will open an input where a user could modify the contents of a specific item. When sent to your reducer, instead of filtering you might consider mapping โ€” i.e. an action where all reviews are returned, but if a review's id matches, the newly submitted content is returned instead.

crud-lab's People

Contributors

lukeghenco avatar dependabot[bot] avatar maxwellbenton avatar rrcobb avatar jeffkatzy avatar lizbur10 avatar nikymorg avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.