'how can i send data to redux correctly?
I am trying to learn Redux. what I want to do: update the store with the data I send to the reducer. what I've done so far:
let reduxData=[1,2,3];
const reduxState = useSelector((state)=>state)
const dispatch = useDispatch();
const {setReduxData} = bindActionCreators(actionCreators, dispatch);
my action:
export const setReduxData = (data) => {
return {
type: 'setReduxData',
payload: data
}
}
my reducer:
export function reducer(state = {data: []}, action) {
switch (action.type) {
case 'setReduxData':
return {
...state,
data: [action.payload]
}
default:
return state
}
}
I am still new to both programming in general and redux so I apologize for any amateur mistakes I surely have made
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
