I am using redux for state management on react-native and I am a total rookie, be warned ;)
I am converting my static data to using the product state instead of an array.
This is my static product array which will later be fetched from an API.
const products = [
{id: 1, title: 'Apple Pie'},
];
On app load I set the state like this:
useEffect(() => {
dispatch(allActions.productActions.setProducts(products))
},[]);
On my view I call the getItem function, which works fine with the static array
function getItem(itemId) {
let obj = products.filter(item => item.id === itemId);
return obj[0];
}
the function returns an undefined object error, because it expects the actual array and not the state object.
The products state looks like that:
[{"products":[{"id":1,"title":"Apple Pie"}]}]
out of that I need:
[{"id":1,"title":"Apple Pie"}]