导入时出现“窗口未定义”错误,react-component-export-image因此我使用动态导入来解决该问题。我不再收到该错误,但现在我收到“exportComponentAsPNG(componentRef)不是函数”。有没有更好的方法来处理“窗口未定义”错误或使用我动态导入的函数的方法?如果没有,是否有不同的 npm 库可以从 React 组件生成图像?
import React, { useRef } from 'react'
// import { exportComponentAsPNG } from 'react-component-export-image' *This gave window not defined error so I used dynamic import*
import dynamic from 'next/dynamic'
import ProductCard from '../ProductCard/ProductCard.component'
import Button from '../Button/Button.component'
const { exportComponentAsPNG } = dynamic(
() => import('react-component-export-image'),
{
ssr: false
}
)
const Plaque = () => {
const componentRef = useRef()
// eslint-disable-next-line react/display-name
const ComponentToPrint = React.forwardRef((props, ref) => { …Run Code Online (Sandbox Code Playgroud)