The method called in action component of redux is not working

54 Views Asked by At
const getProducts = () => async (dispatch) => { 
    try { 
           const data = await fetch("http://localhost:8005/getproducts", 
           {  method: "GET", 
              headers: {     
                 "Content-Type": "application/json"
               }
           });
           const res = await data.json();
           console.log(res);
           dispatch({ type: "SUCCESS_GET_PRODUCTS", payload: res });
    } catch (error) {
           dispatch({ type: "FAIL_GET_PRODUCTS", payload: error.response });
     }
}
export default getProducts;

this method is not working which is in action.js file and is being called from here.

const { products } = useSelector(state => state.getProReducer);
console.log(products)
const dispatch = useDispatch();

useEffect(() => {
    dispatch(getProducts());
});

}

it was working previously but when i restart the server it stopped working.

0

There are 0 best solutions below