I have a reducer inside useContext/provider. I need to validate an action using values from another Provider. Is there a way to retrieve those values from a Provider from within the useReducer hook? Or do I have to try to feed them in as function arguments. Ex:
Reducer
export default function reducer(state: State, action: Action): State {
switch(action.type) {
case "set-amount": {
const { amount } = action.state
const { maxAmount } = useFooContext()
if (amount > maxAmount) // do something
return { ...state, amount }
}
}
}
Provider
export function Provider(...) {
const [state, dispatch] = useReducer(reducer, {}, initState)
return ...
}