关于使用React Hooks 将 props 转化为 state

关于这种情况,一般使用useEffect hook, 监控props的动态即可, 如果有变化,就可以props转化为State, 

  useEffect(() => {
    if (!customizedPage || !customizedEntriesInPage) {
      return;
    }
    setPage(customizedPage);
    setEntriesInPageState({ entriesInPage: customizedEntriesInPage });
  }, [customizedPage, customizedEntriesInPage]);

  

猜你喜欢

转载自www.cnblogs.com/wikiwitang/p/13369891.html