martpet
martpet13mo 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
TheYuriG13mo ago
that's what signals are for, no?
martpet
martpet13mo ago
Yes, but arent' signals only for islands? I haven't used islands yet Actually I can just use ‘export const state = { value: “” }’
TheYuriG
TheYuriG13mo 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
cdoremus13mo 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.