Not getting data when page change from 1 to 2 #10265
mishraasaurabh
started this conversation in
General
Replies: 1 comment
-
From what I saw, you copy the loader data to a state If the param change but it's the same route the loader data will update but React (not Remix, React) will not re mount the component so the state is left untouched Instead use the loader data directly, or move your code to another component and use location.key (from useLocation) to force that other component to re mount on a navigation |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
pls any one can find the solution of that
here,
when page changed from 1 to 2 not getting current page data
import { json, LoaderFunction } from "@remix-run/node";
import { getPosts } from "
/api/posts/new";/types/responseData";import { APIResponse } from "
import { Post } from "
/types/post";/page/Home";import { useFetcher, useLoaderData } from "@remix-run/react";
import { useEffect, useState } from "react";
import Home from "
type LoaderData = {
results: APIResponse<Post[] | []>;
};
export const loader: LoaderFunction = async ({ request }) => {
const url = new URL(request.url);
const page = parseInt(url.searchParams.get("page") || "1", 10);
};
const Dashboard = () => {
const { results } = useLoaderData();
const fetcher = useFetcher();
};
export default Dashboard;
export const getPosts = ({page, limit}: getPostProps) => {
const queryParams = new URLSearchParams({
page: String(page),
limit: String(limit),
});
return request<APIResponse<Post[]>>("GET",
/api/posts?${queryParams.toString()}
);};
Beta Was this translation helpful? Give feedback.
All reactions