Add provider component to context
Hi, is this an anti-pattern in Fresh?
Basically
SomeProvider
is attached to the ctx
via middleware. Use-case is if you want to add server props coming from state
. So instead of doing something like:
It improves DX since user-land wont have to do this anymore. Will it be unique to each request? And if yes, how would you update PageProps
type?4 Replies
The whole Fresh context object is unique for each request.
so the
state
property hanging off of that is unique tooWould you say the code above is anti-pattern? If not, should I put it to state instead? and how do I extend
PageProps
type?
looks good?
Id love to attach it to ctx instead, but not sure how to type itNo, not an antipattern. Custom data is expected to be stored on
ctx.state
which passed through every route or layoutThanks! Would love to extend context type too btw! Is there a way to contribute to this?