Skip to content

How to defer based on a boolean value instead of a promise? #11755

Discussion options

You must be logged in to vote

Nevermind, I figured out the issue {(sessionCookie) => (...)} sessionCookie is just the hasSessionCookies value.

Just a follow up question, is there a way to wait for a value to be true instead of awaiting the promise?
EDIT: I tried implementing a timed await function: (credit to this stackoverflow post)

function waitForSessionCookie() {
  const poll = (resolve: any) => {
    if (checkSessionCookies()) resolve();
    else setTimeout((_: any) => poll(resolve), 400);
  };

  return new Promise(poll);
}

and replaced

return defer({
    hasSessionCookies: checkSessionCookies(),
  });

with

return defer({
    hasSessionCookies: waitForSessionCookie(),
  });

but it kept on showing the error page.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by DanielCoder834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant