Answers
- An action can contain as many properties as we like! It needs to include at least one for the
type
property. It can then include as many other properties as we need for the reducer to change the state, but this is generally lumped into one additional property usually calledpayload
. So, generally, an action will have one or two properties. - We used the
readonly
keyword in the properties in the interface for the state to make it read-only. - The
Provider
component needs to be placed above the components that need access to the store. So, it doesn't need to be right at the top of the tree. - The
useSelector
hook allows a component to select state from the store. - The
useDispatch
hook returns a function that can be used to dispatch an action – it can't be used to dispatch an action directly. Here's the correct way to dispatch an action:const dispatch = useDispatch(); ... dispatch(gettingQuestionAction);
- Yes, a component can have a local...