Code Monkey home page Code Monkey logo

map-dispatch-to-props-lab's Introduction

mapDispatchToProps Lab

Objectives

Implement a mapDispatchToProps() function to connect a Redux action to a component event

Overview

In this lab you will be implementing a mapDispatchToProps() function for an application that helps us keep track of our favorite restaurants. Our React application is kept separate from our Redux application through the use of the Provider component and the connect() function. When you have completed the lab, there should be no reference to the store in any component other than the Provider.

Instructions

Much of the functionality of the app is already built out for you. We have two components: a RestaurantInput component that consists of a simple form to add a new restaurant, and a Restaurants component that renders the names of the restaurants to the page. Redux has already been set up through index.js and the reducer manageRestaurants. In addition, the Restaurants component has been connected to the store and a mapStateToProps() function implemented to provide the list of restaurants to the component as props.

Recall that, in the previous codealong, we wrote both the mapStateToProps and mapDispatchToProps functions in our App.js file. For this application, however, we have separated our form code from the code rendering the list of restaurants. There is no reason we can't use connect() with both components. Your task is to write a mapDispatchToProps() function in the RestaurantInput component, which will allow us to pass dispatched actions as props. Remember that mapDispatchToProps() is provided dispatch as an argument (passed in by connect when called), so we can wrap an imported action with dispatch within mapDispatchToProps(). Don't forget that the action provided in actions/restaurants.js is a function that must be called in order to return the action object.

HINT: remember that connect() passes dispatch as the second argument. Since you won't have a mapStateToProps action in your RestaurantInput component, you can ensure that dispatch is passed to mapDispatchToProps by passing null as the first argument to connect.

map-dispatch-to-props-lab's People

Contributors

danl12186 avatar dependabot[bot] avatar gj avatar ihollander avatar jeffkatzy avatar joshua-miles avatar lizbur10 avatar lukeghenco avatar maxwellbenton avatar mmacdonald1 avatar rrcobb avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

map-dispatch-to-props-lab's Issues

Solution Branch does not include function the lab explicitly asked us to write

The instructions for this lab state:
Redux is already set up through index.js and the reducer manageRestaurants. Write a mapDispatchToProps() function that allows us to pass dispatched actions as props.

But there is not mapDispatchToProps() function in the solution branch. The solution branch offers the shortcut method, which we have not yet learned in the curriculum.

Thank you!

Minor thing (.name vs. .restaurantName)

In restaurants.js, the line for displaying each entered Restaurant tries to reference restaurant.restaurantName, but it should be restaurant.name, and as a result nothing shows up in the Browser besides a bulletpoint. This doesn't actually affect the lab, but I thought it was worth pointing out.

let restaurants = this.props.restaurants.map((restaurant, index) => <li key={index}>{restaurant.restaurantName}</li>);

should be:

let restaurants = this.props.restaurants.map((restaurant, index) => <li key={index}>{restaurant.name}</li>);

The handleOnLocationChange prevents test from passing

The provided code handleOnLocationChange = event => { this.setState({ [event.target.id]: event.target.value }); }

Should be handleOnLocationChange = event => { this.setState({ location: event.target.value }); }

this prevented the final test from passing. The top code snippet was provided and as a student I didnt think we would need to change that section of code based on what the lab is having us practice/apply compared to the previous readme.

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.