Revalidating Multiple Layers Deep
Answered
Arinji posted this in #help-forum
ArinjiOP
Ok so in my page, i get data from a json file like this
And 2 layers deep i call a component, which when a button is clicked awaits a server action, the action being
Thing is, the deleted link dosent seem to be getting removed from the UI.
Btw i dont render the data i get from the json directly, i put them in its own state and render the state
const partnerLinks = (await getJson(
"/files/partners",
"partners",
undefined,
true
)) as typeof PartnerData;export async function getJson(
fileName: string,
tag?: string,
revalidate?: number,
useEditor?: boolean
) {
if (useEditor) {
const file = await unstable_cache(
async () => {
return await fs.readFile(
process.cwd() + `/data${fileName}.json`,
"utf8"
);
},
tag ? [tag] : undefined
)();
console.log(file);
const locContent = JSON.parse(file);
return locContent;
}
const file = await fs.readFile(
process.cwd() + `/data${fileName}.json`,
"utf8"
);
const locContent = JSON.parse(file);
return locContent;
}And 2 layers deep i call a component, which when a button is clicked awaits a server action, the action being
export async function DeleteLink({
linkData,
partnerData,
columnName,
}: {
linkData: PartnersData["Standard"][0]["links"][0];
partnerData: PartnersData["Standard"][0];
columnName: "Standard" | "Featured";
}) {
const partnerLinks = (await getJson(
"/files/partners",
"partners"
)) as PartnersData;
const updatedColumn = partnerLinks[columnName].map((partner) => {
if (partner.name === partnerData.name) {
partner.links = partner.links.filter(
(link) => link.site !== linkData.site
);
}
return partner;
});
const updatedData = {
...partnerLinks,
[columnName]: updatedColumn,
};
await setJson("/files/partners", JSON.stringify(updatedData));
revalidateTag("partners");
await AddToLogs({
description: `Deleted link ${linkData.site} for ${partnerData.name} in ${columnName}`,
path: "/partners",
});
}Thing is, the deleted link dosent seem to be getting removed from the UI.
Btw i dont render the data i get from the json directly, i put them in its own state and render the state
Answered by Arinji
Ok so 2 issues which i fixed,
1) As a dumb dumb, my unstable had the wrong syntax.. i forgot that there were key parts xD
2)The data updates correctly, i just need to update my state with a simple useEffect
1) As a dumb dumb, my unstable had the wrong syntax.. i forgot that there were key parts xD
2)The data updates correctly, i just need to update my state with a simple useEffect
1 Reply
ArinjiOP
Ok so 2 issues which i fixed,
1) As a dumb dumb, my unstable had the wrong syntax.. i forgot that there were key parts xD
2)The data updates correctly, i just need to update my state with a simple useEffect
1) As a dumb dumb, my unstable had the wrong syntax.. i forgot that there were key parts xD
2)The data updates correctly, i just need to update my state with a simple useEffect
Answer