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

Prevent print-only components from rendering when we aren't in the 'print mode'. #39

Open
alex-gokkun opened this issue Jan 31, 2019 · 5 comments

Comments

@alex-gokkun
Copy link

Correct me if I'm wrong but I haven't found an official way for a print-only component not being rendered.
Let's say that I have a component that depends on a plethora of props. Each prop change would trigger a re-render. It's a waste of effort if I'm not actually printing anything at the moment.
By subscribing to beforeprint and afterprint events I got a workaround but I cannot say I'm satisfied with it. It seems to violate separation of conerns.
Are there any plans on supporting this in the library?

@a-x-
Copy link
Owner

a-x- commented Jan 31, 2019

Hm, official way is there. Let me a second

@a-x-
Copy link
Owner

a-x- commented Jan 31, 2019

Did you try <Print printOnly...?

@alex-gokkun
Copy link
Author

Yes, I did. It prevents the component from being displayed but doesn't prevent it from being rendered.

@a-x-
Copy link
Owner

a-x- commented Jan 31, 2019

I got now. Thank you for the case!

There is a reason for this behavior.
If PrintProvider would re-render the children (whole components tree)
state of components will be lost.

I thinked a few minutes right now and realized the solution:
PrintProvider should triggers target re-renderings for printOnly and some another components Through pubsub in the context
(Like ‘redux’ or ‘material ui’ theming does it in its connect/withStyles hocs).

Do you wanna try to implement this?

I can try in a 2-4 next days.

@AustinMutschler
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants