react-skinview3d icon indicating copy to clipboard operation
react-skinview3d copied to clipboard

TypeError: g is undefined in a NextJS project

Open pe3ep opened this issue 9 months ago • 1 comments

When trying to use the library in a Next project, the type error occurs

Sandbox: https://codesandbox.io/p/devbox/trtrms

pe3ep avatar Mar 25 '25 11:03 pe3ep

Me doing this fixed the issue, maybe this helps :)

"use client"
import React, { useEffect } from "react"
import { SkinViewer } from "skinview3d"

export default function PlayerViewer({ uuid }: { uuid: string }) {
  const canvasRef = React.useRef<HTMLCanvasElement>(null)

  useEffect(() => {
    if (!canvasRef.current) {
      return
    }
    const viewer = new SkinViewer({
      canvas: canvasRef.current,
      width: 500,
      height: 500,
    })

    viewer.loadSkin(`https://www.mc-heads.net/skin/${uuid}`)
  }, [canvasRef])

  return <canvas ref={canvasRef} />
}

pe3ep avatar Mar 25 '25 11:03 pe3ep

Should be related to https://github.com/Hacksore/react-skinview3d/pull/167

Hacksore avatar May 04 '25 14:05 Hacksore