How can I show dynamic title in Meta function in loader suspense case? #6073
-
I saw remix don't navigate until the loader completely fetch the data. For that reason I implemented Suspense, defer in that page. Which is working fine. Now the question is how can I show that fetched promise product title into dynamic meta tag? as I can see the Meta function has no option to handle such situations. here is the code I am using now. Please help me export const meta: V2_MetaFunction = ({ data }) => {
const product = data.product;
return [
{
title: data.product.then((prod: Product) => prod.title),
},
];
};
export const loader: LoaderFunction = async ({ params }: LoaderArgs) => {
const productId = params.productId;
const product = axios
.get("http://fakestoreapi.com/products/" + productId)
.then((res) => res.data);
return defer({ product: product });
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
If you need the data from the loader to set the title, then that piece of data can’t be deferred because it’s critical data, so add an await for it to work. Another option can be to use an effect to change the document.title once the promise is resolved. |
Beta Was this translation helpful? Give feedback.
Can't you separate what's critial from what can wait?