Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
65 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...