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

Hooks + Context not working within Tailwind component #1104

Open
aplr opened this issue Dec 18, 2023 · 1 comment
Open

Hooks + Context not working within Tailwind component #1104

aplr opened this issue Dec 18, 2023 · 1 comment

Comments

@aplr
Copy link

aplr commented Dec 18, 2023

The new Tailwind component makes it quite impossible to use hooks or context w/ react email.

As I'm using react-i18next for i18n, I'm using the useTranslation hook. So I'm not having a dynamic use case either, just using available tools.

Also, I'm using context to pass around some shared data without using prop drilling.

My workaround till now was having Tailwind as my root, so it won't interfere w/ context etc.

However, this won't work with the rewrite, as it's now required to have the <head> as a direct descendant of <Tailwind>.

The hooks issue was also mentioned in #1021, and also what's the probable cause:

@gabrielmfern that does seem a little weird to me, as I do expect hooks to run for other "static" use cases like static site generation or server-side rendering, especially as async server side rendering is becoming more of a thing, and indeed hooks run fine with renderToStaticMarkup. React contexts also work fine in static rendering, the issue is with how the tailwind function traverses the component tree and calls components as plain functions: https://github.com/resendlabs/react-email/blob/2374d0d099360c63fe7427febb239776c3bd6b3b/packages/tailwind/src/tailwind.tsx#L95C32-L95C32.

For now my workaround is using <MyReactContext.Consumer>{context => ...}</MyReactContext.Consumer> instead of the hook.

That's interesting, then I think this is an actual issue with the new Tailwind version, can you open an issue on this so we can reference it on a PR and discuss it there?

Originally posted by @gabrielmfern in #1021 (comment)

@gabrielmfern
Copy link
Collaborator

Certainly something we have in mind and that we intend in fixing ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants