-
-
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
React Context not handled correctly (react-redux and react-intl) #522
Comments
A code snippet to replicate this would be great |
https://github.com/ribx/react-pdf-test import React, {Component} from 'react'
import {createStore} from 'redux'
import ReactDOM from 'react-dom'
import {IntlProvider, FormattedMessage} from 'react-intl'
import {Provider as ReduxProvider, connect} from 'react-redux'
import {Document, Page, View, Text, PDFViewer} from '@react-pdf/renderer'
const store = createStore(state => state)
const Connected = connect(state => ({state}))(props => console.log('state', props.state) || props.children)
class App extends Component {
render() {
return (
<div className="App">
<PDFViewer>
<Document>
<Page>
<View>
<Text>
<FormattedMessage id="test">{s => s}</FormattedMessage>
</Text>
</View>
<View>
<Text>
<Connected>
Redux connected component Test
</Connected>
</Text>
</View>
</Page>
</Document>
</PDFViewer>
</div>
)
}
}
ReactDOM.render(
<ReduxProvider store={store}>
<IntlProvider locale="en" messages={{en: {id: "test", defaultMessage: "React PDF Test"}}}>
<App/>
</IntlProvider>
</ReduxProvider>,
document.getElementById('root'),
) I think this is somehow connected to how the new context is working, but I have still problems understanding the concept of react-reconciler. |
Hi @diegomura, any idea how we can solve this problem. Using context API is a common case. |
Hi, just want to mention that I'm having also problems connecting this component to some context, either the Redux one, as well as other used in my current project. Is there something we can do in order to help you? cc @diegomura |
same issue here, can't inject react intl ... an alternative solution is to connect the parent component and pass data into props but still alternative. |
Having same issue on |
I am having the similar issue.
Some of my code for React PDF component are following.
|
I am having the same issue. Any update regarding the same? |
@SrividyaKK It's still silent. |
I see there is a version 2 branch. Has anyone tried this in yet? @SrividyaKK Or have the contributors add this yet? @diegomura |
Nope. Not me. |
I'm using the useContext hook and I always get the value as undefined, any workaround? |
Error: could not find react-redux context value; please ensure the component is wrapped in a
Same issue |
This is an issue on the React side unfortunately. There's an open ticket for awhile now facebook/react#17275. I'll try to reactivate that |
I solved the issue by lift up the state to the parent component. thanks |
Hello, I am still having this issue has anyone come to a solution or work around? |
I am not using react-redux or react-intl but here is what worked for a custom provider I wanted to access within a Document while using PDFViewer. import { CustomProvider } from './CustomProvider';
import {
PDFViewer as PDFViewerOriginal,
PDFViewerProps,
} from '@react-pdf/renderer';
export const PDFViewer = ({ children, ...props }: PDFViewerProps) => {
return (
<PDFViewerOriginal {...props}>
<CustomProvider>
{/**
* Due to a known issue with React, Contexts are not accessible by children of the 'react-pdf' PDFViewer.
* Because 'react-pdf' is a custom renderer and current React limitations, we have to "bridge" contexts.
* We need to subscribe to a context from within the PDFViewer and "bridge" the context by creating a Provider as a
* child of the PDFViewer.
*
* For more info read this: @link https://github.com/diegomura/react-pdf/issues/522#issuecomment-861545047
*/}
{children}
</CustomProvider>
</PDFViewerOriginal>
);
}; Here is a possible solution if your provider is more complex and needs to access some data: import { CustomProvider, CustomContext } from './CustomProvider';
import {
PDFViewer as PDFViewerOriginal,
PDFViewerProps,
} from '@react-pdf/renderer';
import { useContext } from 'react';
export const PDFViewer = ({ children, ...props }: PDFViewerProps) => {
const customContext = use context(CustomContext);
return (
<PDFViewerOriginal {...props}>
<CustomProvider value={customContext}>
{children}
</CustomProvider>
</PDFViewerOriginal>
);
}; You can read more about this solution here: |
Describe the bug
I am using react-redux and react-intl, which both use a provider component and react's context.
When I use a component, in this case on that is connected to the redux store, I get the following error:
Found an issue with react-router, which could be important here:
To Reproduce
Steps to reproduce the behavior including code snippet (if applies):
(I have no time to create a minimal code snippet now, but could do so if someone needs it)
Expected behavior
react-pdf should be able to render components, that rely on reacts context api
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: