79388254

Date: 2025-01-26 09:07:40
Score: 1.5
Natty:
Report link

enter image description hereThis is my working code

import the necessary libraries as bellow for the .tsx file.

import React, { useRef } from 'react';
import { useReactToPrint } from 'react-to-print';

Create necessary button,

<Button
    variant="contained"
    color="primary"
    onClick={() => handlePrint && handlePrint()} // Wrap the call in an anonymous function
>
Print Profile
</Button>

Creat the function,

const printRef = useRef<HTMLDivElement>(null); // Ref for printable content

const handlePrint = useReactToPrint({
    contentRef: printRef,
    documentTitle: `Principal_Profile_${ttUserId}`,
    onAfterPrint: () => console.log('Printing completed'),
});

After these steps I was success and was able to print the content in the typescript file as I needed.

Reasons:
  • Blacklisted phrase (0.5): I need
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Uthpalavi Dias