diegomura / react-pdf

📄 Create PDF files using React
https://react-pdf.org
MIT License
15k stars 1.19k forks source link

React-Redux Provider issue #2431

Open web-shoharab-pk opened 1 year ago

web-shoharab-pk commented 1 year ago

Describe the bug could not find react-redux context value; please ensure the component is wrapped in a I called useSelector hook inside of my pdf component and my pdf component use inside my root file. my root file wrapped by redux provider but I face the issue. How can I solve it? Please help me, Thanks

To Reproduce Steps to reproduce the behavior including code snippet (if applies):

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

You can make use of react-pdf REPL to share the snippet

Expected behavior A clear and concise description of what you expected to happen.

Screenshots image

Desktop (please complete the following information):

fabio-carvalho88 commented 7 months ago

Any solution or workaround?

er-santosh commented 7 months ago

@fabio-carvalho88 @web-shoharab-pk @diegomura In my case i had used const [instance, update] = usePDF({ document }); and i had to wrap the document with redux provider to get it working.

fabio-carvalho88 commented 7 months ago

could you please provide an example? @er-santosh

davbrito commented 2 weeks ago

@web-shoharab-pk The rendering of the pdf is done on a different react root than your react-dom root. Hence you don't have access to the contexts that are on that tree.

You can use the hook useContextBridgefrom its-fine library https://github.com/pmndrs/its-fine?tab=readme-ov-file#usecontextbridge or the react-context-bridge package to solve your use case.