I'm working in React Redux, and I am trying to return a value from a simple array in my reducer. Here are my short files:
App.js
let arr = [{"name": "Matthew"}];
function App() {
const dispatch = useDispatch();
dispatch(action1(arr));
return(
<div>
<List />
</div>
);
}
List.js
function List(){
const val = useSelector(getVals);
return(
<div>
{val}
</div>
)
}
Actions.js
export function action1(arr){
return { type: ADD_STORE, arr};
}
Reducer.js
function AddToStore(state = [], action){
switch(action.type){
case ADD_STORE:
return [...action.name, ...state];
}
}
export default AddToStore;
This is giving me the error "object is not iterable." Why? Instead of an array, if I just pass a string, for example "Matthew", I can print it out fine by returning [...action, ...state].