How to call client-side APIs on the page level? #994
Unanswered
hpohlmeyer
asked this question in
Q&A
Replies: 2 comments
-
Looks like the same issue as #502 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I'm pretty sure the problem is here's the full example: import { useEffect } from 'preact/hooks'
type Props = {
id: string
value: string
}
export default function LocalStorage ( { id, value }: Props ) {
useEffect( () => {
localStorage.setItem( id, value )
}, [ id, value ] )
return <span class='hidden'></span>
} If you found my answer satisfactory, please consider supporting me. Even a small amount is greatly appreciated. Thanks friend! 🙏 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a page with an code input that redirects you to a subroute with that code at the end. Essentially the flow looks like this:
abc
into the inputhttps://my-page.com/abc
That works fine, but now I want to store the code in local storage once it has been validated. And that’s where I am stuck.
Normally, I would use a
useEffect
on the page level to store the param in the local storage, but that would put it into deno’s local storage.I know that I need a dynamic island for client-side interactive content, so I have created an island that only uses hooks and does not render anything:
On my site I am using it like this:
But nothing is written to the local storage, instead I see this error:
Returning a fragment (
<></>
) results in the same error.It only goes away if I return actual content. I could do that and hide it with CSS, but the whole approach feels very hacky.
Is there a proper way to do this? I though about using cookies instead of the local storage, because I could set them in the redirect of the post request handler, but since I never need the information on the server, local storage would be more appropriate.
Beta Was this translation helpful? Give feedback.
All reactions