12 - Strong Typing the State and Actions
In this section we explore Strongly Typing the State and Actions
The official docs say: The createAction function returns a function, that when called returns an object in the shape of the Action interface. The props method is used to define any additional metadata needed for the handling of the action. Action creators provide a consistent, type-safe way to construct an action that is being dispatched.
1. Add Login Action Creators
Action Hygiene
Actions should capture unique events not commands
Try not to reuse actions and make generic actions
Suffix your Action types with their source so you know where they are dispatched from like
Login = '[Login Page] Login'
Let effects and reducers be the decision maker not the component and add multiple cases to a switch statement or effects.
Avoid action sub typing by adding conditional information to a property of an action payload by making multiple actions for each case. This makes it easier to test and avoids complicated conditional logic in effects and reducers.
Write actions first
Great presentation on Actions https://www.youtube.com/watch?v=JmnsEvoy-gY&t=5s
2. Add default state and interface
Update state interface
Also, update the create reducer function to this:
Last updated