sonikjs / sonik

349 stars 9 forks source link

allow layouts to access context #12

Closed yukukotani closed 11 months ago

yukukotani commented 1 year ago

Every handler except LayoutHandler can receive Context as a parameter. This PR allow LayoutHandler to access Context as well.

I know that I'm hasty and need more discussion. I just want to show you what I want by code!

Background

I'm working on https://github.com/kuma-ui/kuma-ui/pull/364. I'd like to use Context as a request-scoped dictionary in LayoutHandler to provide elegant API.

Rough example:

const handler: LayoutHandler = ({ children, head, c }) => {
  return (
    <KumaRegistry context={c}>
      <html lang="en">
        <head>
          {head.createTags()}
          <KumaHead context={c} />
        </head>
        <body>...</body>
      </html>
    </KumaRegistry>
  );
}
yusukebe commented 11 months ago

@yukukotani

Sorry for to be late. LGTM!