Open salememd opened 7 hours ago
Hello. It seems your existing code returns the element itself to the function, rather than the ref to the element.
You should be able to accomplish this same workflow by using lazy print content loading (example).
export const LazyContent = () => {
const reactToPrintContent = () => {
return printComponent(ref.current?.cloneNode(true), true);
};
const handlePrint = useReactToPrint({});
return (
<div>
<button onClick={() => handlePrint(reactToPrintContent)}>
Print
</button>
</div>
);
};
Please let me know if this works for you.
Your existing code is honestly a bit strange (I would not expect to see document.createElement
calls within React code). Is there a reason you are doing it this way instead of rendering the component as standard JSX?
Hi,
In previous version we were able to add dynamic content by simple create html element as following
How can we do the same thing in the new version?
Thanks,