Next.js Discord

Discord Forum

useEffect(() => { const token = Cookies.get("token"); if (!token) { toast.error("Yo

Unanswered
Lionhead posted this in #help-forum
Open in Discord
LionheadOP
CAn Any HElp ME To Solve

16 Replies

@Lionhead CAn Any HElp ME To Solve
hooks can't be called conditionally
paste please all the code of the profileCard.js
remove all the if statements after hooks
LionheadOP
check
@Lionhead Click to see attachment
the if(!token) check
move it after all hooks
LionheadOP
Unhandled Runtime Error TypeError: Cannot read properties of null (reading 'default') Call Stack Next.js renderWithHooks node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (10707:0) updateForwardRef node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (14692:0) beginWork$1 node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (17392:0) beginWork node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (25702:0) performUnitOfWork node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (24553:0) workLoopSync node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (24269:0) renderRootSync node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (24224:0) recoverFromConcurrentError node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (23452:0) performConcurrentWorkOnRoot node_modules\next\dist\compiled\react-dom\cjs\react-dom.development.js (23397:0) workLoop node_modules\next\dist\compiled\scheduler\cjs\scheduler.development.js (261:0) flushWork node_modules\next\dist\compiled\scheduler\cjs\scheduler.development.js (230:0) MessagePort.performWorkUntilDeadline node_modules\next\dist\compiled\scheduler\cjs\scheduler.development.js (534:0)
this error showing when run code
@@ts-ignore the `if(!token)` check
LionheadOP
dont uderstand bro can what you say
have you fixed this line? (im assuming you removed the api before you shared code tho)
Western Sandpiper
you need to move
if (!token) {
    router.push("/auth/login");

    return;
  }


below all the hook calls
Western Sandpiper
yeah
can you give corect code plz