Skip to content

Instantly share code, notes, and snippets.

@fourestfire
Last active April 7, 2017 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fourestfire/37377ae710a484f9a0ace91c917722c0 to your computer and use it in GitHub Desktop.
Save fourestfire/37377ae710a484f9a0ace91c917722c0 to your computer and use it in GitHub Desktop.
Quick notes around redux-react implementation (boilerplate in separate file)

React-Redux Notes

Stuck?

  • Map is not a function? Props are either named incorrectly or not getting passed down properly.
    • Keep in mind props (for ui component) vs this.props (stateful component)
  • Did you bind your function?
  • To access value on forms without keeping track of it on state, we can use event.target.property.value
  • When you're doing a map, remember to return inside the map, and remember to set a key!

React-Redux Implementation Checklist

Main elements

  1. Make a store (takes a reducer / middleware)
  2. Hook up Provider within browser/index.js
  3. Create constants, action creators, and reducers in redux folder (also create async actions if using thunk)
  4. If using react-redux, use mapState, mapDispatch, and connect() to supply all components with state. If using react and redux separately, make sure each component is subscribing and unsubscribing from the store

Other considerations

  1. Use react-router, replace <a href></a> with <Link to={}></Link>
  2. Consider IndexRedirect

Code Examples

Map

{
  props.properties.map(property => {
    return (
      <div key={property.id}> {property.name} </div>
    )
  })
}

Forms:

On Change:
<input onChange={ ((event) => props.methodToExecuteOnChange(event.target.value)) } />
On Submit:
<form onSubmit={this.submit}>

submit(event) {
    event.preventDefault();
    // change the state or something
    // make sure submit is bound
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment