Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
63 views
in Technique[技术] by (71.8m points)

javascript - 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

question from:https://stackoverflow.com/questions/65838440/why-is-my-app-failing-in-a-conditional-operator

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...