hook 渲染问题

  const [, forceUpdate] = useReducer(x => x + 1, 0);
 
某些时候 想让自定义hook去刷新函数组件,那只能在自定义组件中使用useState或者useReducer来强制刷新,达到类似以前forUpdate的效果;
 
useEffect(() => {
    c = headerColor;
    forceUpdate();
  }, [headerColor]);
posted @ 2022-05-07 14:51  太阳东升西落  阅读(88)  评论(0)    收藏  举报