Skip to content

Instantly share code, notes, and snippets.

@Domiii
Last active December 10, 2021 12:04
Show Gist options
  • Save Domiii/9c729922414815b365817570c785d3f8 to your computer and use it in GitHub Desktop.
Save Domiii/9c729922414815b365817570c785d3f8 to your computer and use it in GitHub Desktop.
RTK Notes

Based on:

RTK Setup

Using RTK: add data points

Each time, you want to add a new data point or CRUD operation, do these steps:

  1. Add service
  2. Add slice
  3. Add thunk to wrap service
  4. Add the new thunk to slice via extraReducers.
  5. Add slices/reducers to store

Using RTK: use data points

See: https://redux-toolkit.js.org/tutorials/quick-start#use-redux-state-and-actions-in-react-components

  • Read: useSelector(mySelector)
    • mySelector is a selector function defined near (NOT in!) your slice
  • Write: const dispatch = useDispatch(); ... dispatch(myAction());
    • myAction is either a thunk, returned by createAsyncThunk or
      • any of your slice's reducers

Using RTK - Advanced

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