Open alex-gokkun opened 5 years ago
Hm, official way is there. Let me a second
Did you try <Print printOnly...
?
Yes, I did. It prevents the component from being displayed but doesn't prevent it from being rendered.
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.
Any update on this?
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?