Skip to content
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

Use context instead of injecting props to Document's children #124

Closed
Treora opened this issue Dec 31, 2017 · 5 comments
Closed

Use context instead of injecting props to Document's children #124

Treora opened this issue Dec 31, 2017 · 5 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Treora
Copy link

Treora commented Dec 31, 2017

Currently the <Document> component clones all its children and adds some props so that each <Page> can read these props. The approach has a few downsides however:

  • Adding children other than <Page>s gives trouble. For example, you may want a tree of the shape <Document><Button>Next page</Button><Page /></Document>. The button will also get all the extra props injected, which might break it or cause it to complain. The apparent solution of pulling the <Button> out of the <Document> may not be desirable, as e.g. the button would also be rendered when the document is still loading.
  • One cannot wrap a <Page> inside another element (unless that passes down all props). E.g. <Document><div><Page /></div></Document> would fail.

To overcome these issues, would it perhaps be a good idea to stop injecting props, and instead use React's Context to couple the Document and Page components?

@wojtekmaj
Copy link
Owner

That is a freaking awesome idea! I have a hard time believing I did not think of that up until now. I'll start experimenting right away!

@wojtekmaj wojtekmaj self-assigned this Dec 31, 2017
@wojtekmaj wojtekmaj added the enhancement New feature or request label Dec 31, 2017
@wojtekmaj wojtekmaj added this to the 3.0.0 milestone Dec 31, 2017
@wojtekmaj
Copy link
Owner

If you want to have a look, go to feature/use-context branch. But to implement such a big change, I need to write tons of test beforehand. I plan to do that, but I have issues with binary files in Jest testing environment - I'll keep you updated for sure.

@nnnikolay
Copy link

nnnikolay commented Jan 3, 2018

@wojtekmaj I understand benefits from @Treora but what about official documentation which says

If you want your application to be stable, don’t use context. It is an experimental API and it is likely to break in future releases of React.
....
It is far more likely that Redux is the right solution to your problem than that context is the right solution

@wojtekmaj
Copy link
Owner

Hmmm... I am aware of this, but I think that may be just the thing that would solve our problems. Anyway, I'm not planning to even release an alpha context-based until I have VERY good set of tests. I'm not nearly done with writing unit tests so far.

Once I have an excellent test suite I may consider using context. So far, I only think it's a neat idea and I know that Proof of Concept works as expected.

@wojtekmaj wojtekmaj modified the milestones: 3.0.0, Future Jan 3, 2018
@wojtekmaj
Copy link
Owner

Coming back with a small update:

https://twitter.com/dan_abramov/status/948992659930124293

alexandernanberg pushed a commit to alexandernanberg/react-pdf that referenced this issue Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants