Hi, I am trying to make a plugin panel with react-three/fiber. I found this example and tried to replicate it in my code. https://codesandbox.io/p/sandbox/gifted-varahamihira-rrppl0y8l4?file=%2Fpackage.json%3A14%2C23.
This is my code:
import React, { useRef, useState } from ‘react’
import { PanelProps } from ‘@grafana/data’;
import {SimpleOptions } from ‘types’;
import { css, cx } from ‘@emotion/css’;
import { useStyles2 } from ‘@grafana/ui’;
import { PanelDataErrorView } from ‘@grafana/runtime’;
import * as THREE from ‘three’;
import { Canvas, useFrame } from ‘@react-three/fiber’
import { Sphere, Text, OrbitControls } from ‘@react-three/drei’
interface Props extends PanelProps {}
function Box(props) {
// This reference gives us direct access to the THREE.Mesh object
const ref = useRef()
// Hold state for hovered and clicked events
const [hovered, hover] = useState(false)
const [clicked, click] = useState(false)
// Subscribe this component to the render-loop, rotate the mesh every frame
useFrame((state, delta) => (ref.current.rotation.x += delta))
// Return the view, these are regular Threejs elements expressed in JSX
return (
<mesh
{…props}
ref={ref}
scale={clicked ? 1.5 : 1}
onClick={(event) => click(!clicked)}
onPointerOver={(event) => (event.stopPropagation(), hover(true))}
onPointerOut={(event) => hover(false)}>
<boxGeometry args={[1, 1, 1]} />
<meshStandardMaterial color={hovered ? ‘hotpink’ : ‘orange’} />
)
}
export const SimplePanel: React.FC = ({options, data, width, height, fieldConfig, id }) => {
if (data.series.length === 0) {
return ;
}
return (
This is a example
<Canvas>
<ambientLight intensity={Math.PI / 2} />
<spotLight position={[10, 10, 10]} angle={0.15} penumbra={1} decay={0} intensity={Math.PI} />
<pointLight position={[-10, -10, -10]} decay={0} intensity={Math.PI} />
<Box position={[-1.2, 0, 0]} />
<Box position={[1.2, 0, 0]} />
<OrbitControls />
</Canvas>
</div>
);
};
This is I see after the code rendered. The output is not what I expected.
An unexpected error happened
TypeError: undefined is not an object (evaluating 'ReactCurrentActQueue.current')
Canvas@
FiberProvider@
CanvasWrapper
div
SimplePanel@
Thank you for your help!!!