0

I have the below package.json, i installed three, three/drei and three/fiber and three/postprocessing

{
  "dependencies": {
    "@react-three/drei": "9.14.3",
    "@react-three/fiber": "8.0.26",
    "@react-three/postprocessing": "2.4.4",
    "three": "^0.141.0"
  }
}

the current code is adding a canvas object into the react application, Box is just a component returning a mesh element


import React, { Suspense } from "react";
import { Canvas } from "@react-three/fiber";
import Box from "./Box";
const ThreeD = () => { 
  return (
    <div>
      <Suspense fallback={null}>
        <Canvas shadows>
          <Box />
        </Canvas>
      </Suspense>
    </div>
  );
};

on the load of the page i got the below issue:

error on load I tried using the useMemo as below, but the same issue remains,

import React, { Suspense, useMemo } from "react";
import { Canvas } from "@react-three/fiber";
import Box from "./Box";
const ThreeD = () => {
  const Canv = useMemo(() => {
    return (
      <Canvas>
        <Suspense fallback={null}>
          <Box />
        </Suspense>
      </Canvas>
    );
  });
  return (
    <div>
      <Canv />
    </div>
  );
};

export default ThreeD;

Node version: 8.19.2

the issue is originated from the file :(react-three-fiber.esm.js:119:1) at the code : React.useMemo(() => extend(THREE), []);

2 Answers 2

1

I think it can help you. You should add dependencies array in useMemo and use result of useMemo correct.

import React, { Suspense, useMemo } from "react";
import { Canvas } from "@react-three/fiber";
import Box from "./Box";

const ThreeD = () => {
  const Canv = useMemo(() => (
      <Canvas>
        <Suspense fallback={null}>
          <Box />
        </Suspense>
      </Canvas>
  ), []);
  
  return (
    <div>
      {Canv}
    </div>
  );
};

Sign up to request clarification or add additional context in comments.

1 Comment

i tried adding this adjustment, the issue remained the same, as if its something related to their library, because the issue is originated from the file :(react-three-fiber.esm.js:119:1) at the code : React.useMemo(() => extend(THREE), []);
0

I found the issue, I was installing the packages outside the main project folder

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.