#Display Blog Post HTML after fetch?

21 messages · Page 1 of 1 (latest)

unreal oak
#

I'm trying to display some blog post content that is sent via the API as a long HTML string. I currently have reference to a div which I update inside the onMount function by doing postContent.innerHTML = post()?.content!. However, this method feels very tacky and the screen flashes once the content is appended to the postContent div. Is there a convenience function available that I can use to accomplish this?

last moth
unreal oak
#

post() is this object and I'm trying to render the content field containing HTML

#

It comes from routeData

last moth
unreal oak
#

Just shared that with you

last moth
#

Ah

#

I've never used createRouteData like that. Looking to see what it returns....

unreal oak
#

Give me a sec

last moth
#

Are you exporting that as routeData from your page .... and then 'useRouteData` in your component?

unreal oak
#

I'm using the solid-movies app as the base of my app

#

I'm using the exact same function they use inside the movie's detail page

#

Here's what usePost() function returns to the component

#

Similar to going to this page: https://solid-movies.app/movie/76600

last moth
#

<div innerHTML={post()...} />

unreal oak
#

Yeah, I just saw that on StackOverflow too

#

Let me give it a try

last moth
#

Not sure if post() will initially be undefined so you might need to guard that (with a default or <Show>) ...or maybe not.

unreal oak
#

Boom! that's it

#

Yes, I plan on doing that