Unable to map data from api since trying to flesh out redux. Data is available in redux web tools in the Action tab. My variable products brings back an empty array.
export default function HomeScreen() {
const dispatch = useDispatch();
const productList = useSelector((state) => state.productList);
const { loading, error, products } = productList;
useEffect(() => {
dispatch(listProducts());
}, [dispatch]);
return (
<div>
{loading ? (
<LoadingBox></LoadingBox>
) : error ? (
<MessageBox variant="danger">{error}</MessageBox>
) : (
<div>
{
products?.map((product) => (
<Product key={product._id} product={product}></Product>
))
}
</div>
)}
</div>
)
}
export const listProducts = () => async (dispatch) => {
dispatch({
type: PRODUCT_LIST_REQUEST
});
try {
const { data } = await axios.get('/api/products');
dispatch({ type: PRODUCT_LIST_SUCCESS, payload: data })
} catch (error) {
dispatch({ type: PRODUCT_LIST_FAIL, payload: error.message })
}
}