ServerSide fetching for metatags
Hi I am looking for server side fetching for open graph metatags. I want to execute fetch on server side and then render page with title and metatags filled in. If returned result from fetch has length of 0 redirect user to
/404
page.
My meta tags setup
It works but does show nothing when the link is sent.
Source code of MetaPageProvider
17 Replies
Source code of useAPIFetch
Add
{ deferStream: true}
to the createResource
, that'll delay the server from sending a response until the data is readyOk ok
I'll try that
Ah also, don't destructure props in
MetaPageProvider
Why?
Destructuring props is a no-no in solid
Oh dear
I used to do this when I was using react
I use it every where tbh
🤣
If it's really a problem you can add this https://github.com/orenelbaum/babel-plugin-solid-undestructure
GitHub
GitHub - orenelbaum/babel-plugin-solid-undestructure: A Babel plugi...
A Babel plugin for SolidJS that allows you to destructure component props without losing reactivity. - orenelbaum/babel-plugin-solid-undestructure
Oh ok ok
Also, assigning to
image_url
in the component body may not have the effect you expect, since the component body only runs once
if the image_url
prop changes (which it probably will when depending on a resource) then the url you're constructing won't update
Make it a function that you call in the jsx instead
I mean i get the image URL from api
That's fine, i mean it'll change when rendering
It'll start as
undefined
and then update to the actual value once fetched
Or maybe start as ""
since you've got a default value there
But yeah since the component body doesn't re-run the full url won't get recalculated unless you do it in its own functionOne more question do you suggest that I should build components like this instead of deconstructing their props?
Yeah
ok is it a good practise?
Yeah since things won't work properly if you destructure
I am not gonna lie my project got kinda messy I will clean it up. That's why I am asking
I will refactor it a little bit