Skip to content

onMount doesn't work for Atoms referenced in useAtomCallback #2053

Answered by dai-shi
zhmushan asked this question in Bug report
Discussion options

You must be logged in to vote

I see.

I don't know what the best practice of jotai is for dealing with this scenario. (Because I want to manually control the Loading status of the page

If you want such a control, it means it's not declarative, but imperative. Whatever it means, it's something like this in Jotai best practice:

export const tableAFilterAtom = atom({});
export const tableADataAtom = atom({});
export const setTableADataAtom = atom(null, async (get, set) => {
  const filter = get(filterAtom);
  const tableAFilter = get(tableAFilterAtom);

  try {
    const data = await fetch("/tableA", {
      method: "POST",
      body: JSON.stringify({ ...filter, ...tableAFilter })
    });
  } catch {}

  set(tableAData…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@zhmushan
Comment options

@dai-shi
Comment options

@zhmushan
Comment options

@dai-shi
Comment options

Answer selected by zhmushan
@zhmushan
Comment options

@Qquanwei
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2052 on July 31, 2023 04:38.