agentcooper / react-pdf-highlighter

Set of React components for PDF annotation
https://agentcooper.github.io/react-pdf-highlighter/
MIT License
1.09k stars 428 forks source link

Use React 16 portals #10

Closed agentcooper closed 2 months ago

agentcooper commented 6 years ago

Code should use portals instead of calling ReactDOM.render inside renderHighlights.

idibidiart commented 6 years ago

hey nice work

what's the advantage of using portals here?

agentcooper commented 6 years ago

Thank you.

At the moment I use ReactDOM.render to render highlights inside the existing PDF.js structure. The disadvantage is the loss of the context. If you use Redux in your app, the Highlight component won't have access to the store, so that you'll need to wrap Highlight in Provider manually.

idibidiart commented 6 years ago

Awesome.

For others who are curious:

"Features like context work exactly the same regardless of whether the child is a portal, as the portal still exists in the React tree regardless of position in the DOM tree." source: React docs on Portals

Makes sense in case of Redux but I agree it's a nice to have.

Great great work. Looking forward to hacking on it!