martpet
martpet2y ago

Fresh: global state

Is it possible to have a global state that can be accessed from anywhere? Currently I'm passing the Request object to many deeply nested server-rendered components, because I need to read the request hostname from it. I wish there was a way I could skip passing it through props.
4 Replies
TheYuriG
TheYuriG2y ago
that's what signals are for, no?
martpet
martpetOP2y ago
Yes, but arent' signals only for islands? I haven't used islands yet Actually I can just use ‘export const state = { value: “” }’
TheYuriG
TheYuriG2y ago
from inside a function? islands are for reactive data. you need to have one to be able to change data dynamically, otherwise the render is the final state
cdoremus
cdoremus2y ago
Check out my blog post and the code that goes with it: https://deno-blog.com/Using_Preact_Signals_with_Fresh.2022-11-01
Craig's Deno Diary
Craig's Deno Diary is a blog that covers the JavaScript and TypeScript runtime Deno and focuses on how to write Deno programs and use Deno libraries.

Did you find this page helpful?