981377660LMT / ts

ts学习
6 stars 1 forks source link

react hooks 顺序报错 #414

Open 981377660LMT opened 8 months ago

981377660LMT commented 8 months ago

hooks 前 return 导致 hooks 未执行完(顺序不对),引发 bug。

image
index.tsx:33 Warning: React has detected a change in the order of Hooks called by wrappedComponent. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://fb.me/rules-of-hooks

   Previous render            Next render
   ------------------------------------------------------
1. useState                   useState
2. useCallback                useCallback
3. useRef                     useRef
4. useDebugValue              useDebugValue
5. useEffect                  useEffect
6. useRef                     useLayoutEffect
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    in wrappedComponent (at filter-area/index.tsx:61)
    in div (at filter-area/index.tsx:90)
    in div (at filter-area/index.tsx:84)
    in FilterArea (at table/index.tsx:472)
    in div (at table/index.tsx:450)
    in div (at table/index.tsx:446)
    in div (at table/index.tsx:443)
    in ForwardRef (at xtable.tsx:63)
    in div (at xtable.tsx:63)
    in div (at xtable.tsx:62)
    in XTable (at home/index.tsx:98)
    in div (at home/index.tsx:97)
    in Home (at main.tsx:10)
    in Route2 (at main.tsx:9)
    in Switch2 (at main.tsx:8)
    in Router2 (created by BrowserRouter2)
    in BrowserRouter2 (at main.tsx:7)

react-dom.development.js:14748 Uncaught TypeError: Cannot read properties of undefined (reading 'length')
    at areHookInputsEqual (react-dom.development.js:14748:38)
    at updateEffectImpl (react-dom.development.js:15313:11)
    at updateLayoutEffect (react-dom.development.js:15351:10)
    at Object.useLayoutEffect (react-dom.development.js:15911:14)
    at Object.useLayoutEffect (react.development.js:1513:21)
    at useQueuedForceUpdateBlock (useQueuedForceUpdate.js:25:15)
    at useObserver (useObserver.js:83:12)
    at wrappedComponent (observer.js:24:16)
    at renderWithHooks (react-dom.development.js:14803:18)
    at updateFunctionComponent (react-dom.development.js:17034:20)