Jul 13, 2023
0
Level 4
Loading via infinite scroll,?
Posts are passed in via:
export default function Index({ posts }) {
Then set to a localPosts var via:
const [localPosts, setLocalPosts] = useState(posts);
Then, new posts are loaded via infinite scroll
useEffect(() => {
if (inView && !isLoading) {
setIsLoading(true);
if (posts.next_page_url === null) {
return;
}
router.get(
posts.next_page_url,
{},
{
preserveState: true,
preserveScroll: true,
only: ["posts"],
onSuccess: () => {
console.log(localPosts);
console.log(posts);
},
}
);
}
}, [inView, isLoading, localPosts, posts]);
In onSuccess I just am logging things for now, but there is an issue.
localPosts logs rows 1-20.
posts also logs rows 1-20. This should log rows 21-40. It is like onSuccess is running before the posts prop has had a chance to filter down.
Any ideas?
Please or to participate in this conversation.