You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
PDFViewer component prevents passing context using react hooks.
To Reproduce
interfaceDataContext{data: {nested: string;}|null;}constdefaultValue: DataContext={data: null};constDataContext=React.createContext(defaultValue);// real context loaded via ajax constgetDataContextValue=()=>({data: {nested: "value"}});// app rootconstApp: React.FC=({ children })=>{return(<DataContext.Providervalue={getDataContextValue()}>{children}</DataContext.Provider>);};// test pdf doc, that uses react hook contextconstMyPdf: React.FC=()=>{const{data: { nested }}=React.useContext(DataContext);return(<Document><Page><Text>{nested}</Text></Page></Document>);};// this will throw error during deconstructing because datacontext will have default value // and not value from App DataContext.ProviderconstThrowsError: React.FC=()=>{return(<PDFViewer><MyPdf/></PDFViewer>);};// this will render successfully constWorkaroud: React.FC=()=>{return(<DataContext.Consumer>{dataContext=>(<PDFViewer><DataContext.Providervalue={dataContext}><MyPdf/></DataContext.Provider></PDFViewer>)}</DataContext.Consumer>);};// renderReactDOM.render(<App><ThrowsError/><Workaroud/></App>,root);
Expected behavior
PDFViewer should pass context into document without needs for manually pass context as in Workaroud component above.
Desktop:
OS: windows 10
Browser chrome
React-pdf version 1.6.7
The text was updated successfully, but these errors were encountered:
Describe the bug
PDFViewer component prevents passing context using react hooks.
To Reproduce
Expected behavior
PDFViewer should pass context into document without needs for manually pass context as in Workaroud component above.
Desktop:
The text was updated successfully, but these errors were encountered: