Can data be retrieved again from loader in Remix? #9033
-
Hello everyone, I'm a newcomer to JavaScript and Remix. I'd like to inquire about how to fetch data multiple times from a Promise. Does Remix integrate similar functionality? Let's take the example below: suppose there's a Task currently in progress, and we need to display its information (such as status) to the user. You can imagine that the Task exists in MySQL. Currently, we use However, the user wishes to add a feature that automatically retrieves Task data every 5 seconds. They want to call Currently, I've thought of 2 methods:
Therefore, I'd like to inquire if Remix provides functionality to fetch data from a Promise again. I haven't found a solution in the documentation or through Google. Thank you. export const loader = async ({ request }) => {
const id = 1;
const taskPromise = getTask(id);
return defer({
taskPromise: taskPromise
});
};
export default function Index() {
const { taskPromise } = useLoaderData();
return (
<Suspense>
<Await resolve={taskPromise}>
{(task) => { // TODO Show the data }}
</Await>
</Suspense>
)
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Search for |
Beta Was this translation helpful? Give feedback.
-
Here's an article that shows how to use the https://sergiodxa.com/tutorials/keep-your-loader-data-fresh-in-remix |
Beta Was this translation helpful? Give feedback.
Here's an article that shows how to use the
useRevalidator
hook to keep your local data fresh.https://sergiodxa.com/tutorials/keep-your-loader-data-fresh-in-remix