Skip to content

Instantly share code, notes, and snippets.

@diogorusso
Last active October 29, 2018 03:43
Show Gist options
  • Save diogorusso/57cf0c5b4ec6f3960ec366ebbe3492cc to your computer and use it in GitHub Desktop.
Save diogorusso/57cf0c5b4ec6f3960ec366ebbe3492cc to your computer and use it in GitHub Desktop.

React

  • Create React App
  • Redux
  • React Router
  • Scss Modules
  • Storybook

https://thinkster.io/tutorials/create-react-app

Redux is a predictable state container for JavaScript apps. It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. -Redux Docs

The fundamental concepts in Redux are called "stores" and "actions"

reducer receives both the current state and the action as parameters, and returns the modified state.

reducer should not have any side-effects, that is, if you call a reducer with the same state and the same action, you should always get the same result.

good practice to encapsulate as much of your application logic as possible in reducers, because, since your reducers don't rely on side-effects or global state, they're really easy to test, debug, and refactor.

A store has three functions that you're going to be using in this course:

getState - fetches the current state of a store dispatch - fires off a new action subscribe - fires a callback everytime there's a new action after a reducer's action

We subscribe to the redux store and call React's setState() function every time the store changes so we always get the newly reduced state. React calls the render() function every time the component's state changes, which "renders" the component.

To mutate(change) the redux state, you need to dispatch an action. Recall that an action is the 2nd parameter that gets passed to your reducer. An action is an object that tells your reducer what happened (e.g. toggle, click, etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment