Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow layouts to access context #12

Merged
merged 1 commit into from
Nov 29, 2023
Merged

Conversation

yukukotani
Copy link
Contributor

@yukukotani yukukotani commented Nov 1, 2023

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 kuma-ui/kuma-ui#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>
  );
}

@@ -68,3 +69,5 @@ export type Route<E extends Env = Env, N = Node> = {
}

export type AppRoute<E extends Env = Env> = (app: Hono<E>) => void

export type LayoutContext = Omit<Context | 'render', 'setRenderer'>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would lead unexpected behavior to override the rendering in layouts, so omitting them here.

@yusukebe
Copy link
Collaborator

@yukukotani

Sorry for to be late. LGTM!

@yusukebe yusukebe merged commit 45ae97c into sonikjs:main Nov 29, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants