trevorwhitney / react-grade-book

1 stars 0 forks source link

Extraneous Code #1

Open alexprice1 opened 9 years ago

alexprice1 commented 9 years ago

@trevorwhitney,

I am using your project to understand redux. I see here that you are including getStudents within your GradeBook component. Is this extraneous?

If it is not extraneous, how is it being used?

The lines of code are:

  componentDidMount() {
    const {getStudents} = this.props
    getStudents()
  }
trevorwhitney commented 9 years ago

@chapinkapa in terms of the current code, it's a little extraneous because I'm using dummy data here, so the list of students will always be the same. However, in a real application that gets data from an API, you would want to load this data from the server when mounting the component. You do this by calling the getStudents() action creator, which in turn will cause a getStudents action object to be dispatched to your reducers. In a real application, the getStudents() action creator would issue the ajax call to the API, and put the results in the action, so the reducer can pull it off. For more information, check out the redux docs around Async Actions.

alexprice1 commented 9 years ago

Got it, thanks @trevorwhitney, helps me understand how I would wire it up for data from the server.