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

fix: make children optional #276

Merged
merged 1 commit into from
Mar 19, 2024
Merged

fix: make children optional #276

merged 1 commit into from
Mar 19, 2024

Conversation

Innei
Copy link
Contributor

@Innei Innei commented Mar 18, 2024

Make children optional. Because children are not required, as in the following usage, children is not passed in explicitly. We can ensure that types is compatible with the original version.

const baseContexts: JSX.Element[] = [
  <ThemeProvider key="themeProvider" />, // here, `children` is not passed.
  <JotaiStoreProvider key="jotaiStoreProvider" />,
]

export function WebAppProviders({ children }: PropsWithChildren) {
  return (
    <ProviderComposer contexts={baseContexts}>
      {children}
    </ProviderComposer>
  )
}

export const ProviderComposer: Component<{
  contexts: JSX.Element[]
}> = ({ contexts, children }) => {
  return contexts.reduceRight((kids: any, parent: any) => {
    return React.cloneElement(parent, { children: kids })
  }, children)
}

Thanks, @pacocoursey

Signed-off-by: Innei <i@innei.in>
Copy link

vercel bot commented Mar 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-themes-basic ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2024 11:10am
next-themes-tailwind ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2024 11:10am
next-themes-with-app-dir ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2024 11:10am

Copy link
Owner

@pacocoursey pacocoursey left a comment

Choose a reason for hiding this comment

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

Fair enough!

@pacocoursey pacocoursey merged commit 060a000 into pacocoursey:main Mar 19, 2024
5 checks 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