-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 <Document> to be wrapped by context provider Elements in node #1371
Comments
Note: I’ve seen a similar request for this in this issue. However, this is on the web/dom side, whereas my use case is on the node/server side. |
This is an issue on the React side unfortunately. There's an open ticket for awhile now facebook/react#17275. I'll leave #522 to register this issue. Node or web in this case I don't think it changes, since it's on the isomorphic part of React |
Thank you for the quick response! I’ve tried to dive into react-reconciler but it’s quite advanced. If it helps, I’m not trying to share contexts,
I’m just not entirely sure where this should go. |
I'm successfully providing a <Document author="Diasyst">
<ThemeProvider>
<Page size="A2" orientation="portrait" style={{ paddingBottom: FOOTER_HEIGHT }}>
{
patient?.reportData && (
<PdfBillingReport
patient={patient}
data={patient.reportData}
reportedOn={DateTime.now().toISODate()}
/>
)
}
</Page>
</ThemeProvider>
</Document> And here's the provide const ThemeProvider = ({ children }) => {
const theme = useColorScheme();
return (
<StylesProvider injectFirst>
<MuiThemeProvider theme={theme}>
<EmotionCacheProvider value={emotionCache}>
<EmotionThemeProvider theme={theme}>
{children}
</EmotionThemeProvider>
</EmotionCacheProvider>
</MuiThemeProvider>
</StylesProvider>
);
}; I'm successfully using Why won't that work for your case, perhaps the Provider is not returning children directly but adds some element - div? |
Actually that could work! I assumed |
Worked! Successfully put my Providers in my Document before my Pages. Thank you so much for your help! |
Hey guys, sorry to revive a dead thread but I'm just a bit curious about this. @kidroca's solution works for my use case so no problems there, but just for testing sake, I tried moving my Context.Provider outside of the PDFViewer that I am rendering and the context no longer updates for components within my Document (which is wrapped by the PDFViewer). Just wondering if anyone knows why that would be the case? Is it somehow related to the fact that PDFViewer extends React.Component<...> and not React.Component<React.PropsWithChildren<...>>? Apologies if this is an obvious question 😄 This works (meaning components inside can access the stored context):
This does not:
|
Is your feature request related to a problem? Please describe.
I want to use the
renderToFile
method in node to generate a PDF. I also want to use thereact-intl
library to provide messages. I therefore want to consume context from within the from the parent .Describe the solution you'd like
I would like for react-pdf to drill-down within the tree that I provide for the and set it as the root node. It should no longer assume that it is the first child. This should only be used within the node context, there are no user interactions and therefore no reason why doing this would trigger re-renders or any other “bad” behaviour. This functionality would only be used for high-level context providers like . It would not be used to create a multi-node tree higher than the .
Describe alternatives you've considered
I haven’t seen anyone try to implement an intl library with react-pdf, so not sure it has been done.
Additional context
I am using a build process which will wrap the with and then try to render a file.
The text was updated successfully, but these errors were encountered: