How do i naviagte through multiple pages and donot reload the whole page ex.the api request
Answered
Small Greek domestic dog posted this in #help-forum
Small Greek domestic dogOP
due to which there is lot of delay in ui experinece
any suggestion
any suggestion
Answered by B33fb0n3
use a clientside libariy to fetch data clientside. You can use react query or swr or any other. With them, you have more control over your clientside data. If you don't need to fetch your data inside a client component, fetch it serverside and pass the fetched data down to your client component via props
10 Replies
@Small Greek domestic dog due to which there is lot of delay in ui experinece
any suggestion
normally that happens automatically with the browser cache. By default this cache will be revalidated automatically after 30 seconds. So when you navigate to one page (A) and then navigate to another page (B) and navigate back to the first page (A), page (A) should load instantly.
Check your nextjs config, if you might disabled or reduced your browser cache
Check your nextjs config, if you might disabled or reduced your browser cache
@Small Greek domestic dog solved?
Small Greek domestic dogOP
No
@Small Greek domestic dog No
what else do you need to solve your issue?
Small Greek domestic dogOP
"use client";
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { useStore } from '../libs/store';
import { CustomKanban } from '../CustomKanban';
import { Router } from 'next/router';
import { useRouter } from 'next/navigation';
interface User {
id: string;
uniqueId: string;
tasks: Card[];
}
interface Card {
title: string;
description: string;
priority: 'HIGH' | 'MEDIUM' | 'LOW';
id: string;
column: string;
}
const Page: React.FC = () => {
const { userId } = useStore();
const [data, setData] = useState<User | null>(null);
const [uniqueId, setUniqueID] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (userId) {
setUniqueID(userId);
}
}, [userId]);
useEffect(() => {
const fetchData = async () => {
if (!uniqueId) return;
setLoading(true);
try {
const response = await axios.post('/api/getData', { uniqueId });
setData(response.data);
} catch (error) {
console.error('Error fetching data:', error);
} finally {
setLoading(false);
}
};
fetchData();
}, [uniqueId]);
if (loading) {
return <div>Loading...</div>;
}
return (
<div>
<CustomKanban data={data?.tasks} />
</div>
);
};
export default Page;
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import { useStore } from '../libs/store';
import { CustomKanban } from '../CustomKanban';
import { Router } from 'next/router';
import { useRouter } from 'next/navigation';
interface User {
id: string;
uniqueId: string;
tasks: Card[];
}
interface Card {
title: string;
description: string;
priority: 'HIGH' | 'MEDIUM' | 'LOW';
id: string;
column: string;
}
const Page: React.FC = () => {
const { userId } = useStore();
const [data, setData] = useState<User | null>(null);
const [uniqueId, setUniqueID] = useState<string | null>(null);
const [loading, setLoading] = useState(true);
useEffect(() => {
if (userId) {
setUniqueID(userId);
}
}, [userId]);
useEffect(() => {
const fetchData = async () => {
if (!uniqueId) return;
setLoading(true);
try {
const response = await axios.post('/api/getData', { uniqueId });
setData(response.data);
} catch (error) {
console.error('Error fetching data:', error);
} finally {
setLoading(false);
}
};
fetchData();
}, [uniqueId]);
if (loading) {
return <div>Loading...</div>;
}
return (
<div>
<CustomKanban data={data?.tasks} />
</div>
);
};
export default Page;
@B33fb0n3 can u help
what i want to do is wheneever i reload page the request should go
but whenever i reload the request isnt going
what i want to do is wheneever i reload page the request should go
but whenever i reload the request isnt going
@Small Greek domestic dog <@301376057326567425> can u help
what i want to do is wheneever i reload page the request should go
but whenever i reload the request isnt going
use a clientside libariy to fetch data clientside. You can use react query or swr or any other. With them, you have more control over your clientside data. If you don't need to fetch your data inside a client component, fetch it serverside and pass the fetched data down to your client component via props
Answer
@Small Greek domestic dog solved?
Small Greek domestic dogOP
just used different method but yah
happy to help