This repository was archived by the owner on Jan 1, 2025. It is now read-only.
Refresh selector & update UI #996
Unanswered
ivanjeremic
asked this question in
Q&A
Replies: 2 comments 5 replies
-
|
What we usually do is have an atom solely for the purpose of refreshing. // increment this to refrseh databaseListSelector
export const databaseListSelectorRefresh = atom({
key: 'databaseListSelector_refresh',
default: 0,
});
export const databaseListSelector = selector({
key: 'databaseListSelector',
get: async ({ get }) => {
// create a dependency so it becomes refreshable
get(databaseListSelectorRefresh);
// do the actual data fetching
const databaseList: any | string[] = await getDatabaseList();
return databaseList;
},
});And then when we need to refresh we do export default function MyRefreshButton() {
const refresher = useSetRecoilState(databaseListSelectorRefresh);
return <button onClick={() => refresher(x => x+1)}>
Re-fetch data
</button>
} |
Beta Was this translation helpful? Give feedback.
3 replies
-
|
Please see this section in the documentation for some examples of query refreshing. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, What Is the easiest way to refresh a selector that fetches some async data and updates the UI? Do I need to update my UI manually using a
useEffect?In the docs it says: Query Refresh
Selector evaluation should provide a consistent value for a given state based on input (dependent state or family parameters)But my selector is fetching some data without depending on any atom because I don't need atoms for it, so am I doing something wrong here?
Beta Was this translation helpful? Give feedback.
All reactions