Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unintended state change #604

Open
incompletude opened this issue Jul 24, 2024 · 0 comments
Open

Unintended state change #604

incompletude opened this issue Jul 24, 2024 · 0 comments

Comments

@incompletude
Copy link

For some reason, setting permissionCookie will trigger a state change on userCookie.


  const COOKIE_OPTIONS = { path: "/" }
  const USER_COOKIE_NAME = "cookie1"
  const PERMISSION_COOKIE_NAME = "cookie2"

  const [userCookieStore, setUserCookie, removeUserCookie] = useCookies([USER_COOKIE_NAME])
  const [permissionCookieStore, setPermissionCookie, removePermissionCookie] = useCookies([PERMISSION_COOKIE_NAME])

  useEffect(() => {
    setUserCookie(USER_COOKIE_NAME, { test: 1 }, COOKIE_OPTIONS)
  }, [])

  useEffect(() => {
    const userCookie = userCookieStore[USER_COOKIE_NAME]

    console.log(userCookie)
  }, [userCookieStore])

  setTimeout(() => {
    setPermissionCookie(PERMISSION_COOKIE_NAME, { test: 2 }, COOKIE_OPTIONS)
  }, 5000)

According to the docs, it should behave differently, since deps "let you optionally specify a list of cookie names your component depend on or that should trigger a re-render".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant