jeudi 21 janvier 2021

Why is my app failing in a conditional operator?

my code is

export default function useFetch(fetchFunction, param) {
  const cache = useContext(cacheContext);
  const [state, dispatch] = useReducer(fetchReducer, initialValue);
  useEffect(() => {
    if (cache.page[param]) {
      dispatch({ type: ACTIONS.success, payload: cache.page[param] });
      console.log("cache");
      return;
    }
                  // other code below
)

But my app is failing in the conditional operator. Im expecting that if cache.page[param] is empty, keep executing the code below. For example, if i got the param "0" i get the error "TypeError: Cannot read property '0' of null" and my app crashes

Aucun commentaire:

Enregistrer un commentaire