admin管理员组文章数量:1435859
I keep trying to use useRender that I imported from
import { Canvas, useRender } from 'react-three-fiber';
const App = () => {
const meshRef = useRef();
const [hovered, setHovered] = useState(false);
const [active, setActive] = useState(false);
const props = useSpring({
scale: active ? [4, 4, 4] : [2, 2, 2],
color: hovered ? "red" : "hotpink"
});
useRender(() => {
meshRef.current.rotation.y += 0.01
})
It keeps giving me an error however that 'useRender is not exported from 'react-three-fiber'. When I go to the docs (/4-hooks) it says that it can be exported.
Anyone have any idea whats going on? I'm following along this tutorial
I keep trying to use useRender that I imported from
import { Canvas, useRender } from 'react-three-fiber';
const App = () => {
const meshRef = useRef();
const [hovered, setHovered] = useState(false);
const [active, setActive] = useState(false);
const props = useSpring({
scale: active ? [4, 4, 4] : [2, 2, 2],
color: hovered ? "red" : "hotpink"
});
useRender(() => {
meshRef.current.rotation.y += 0.01
})
It keeps giving me an error however that 'useRender is not exported from 'react-three-fiber'. When I go to the docs (https://inspiring-wiles-b4ffe0lify.app/4-hooks) it says that it can be exported.
Anyone have any idea whats going on? I'm following along this tutorial https://www.youtube./watch?v=1rP3nNY2hTo
Share Improve this question asked Jul 10, 2020 at 16:14 zartemiezartemie 211 silver badge4 bronze badges4 Answers
Reset to default 3Instead of useRender
use useFrame
, it will be fine.
useRender is very old, it's called useFrame and also works a little different. the only official docs atm are here: https://github./react-spring/react-three-fiber/blob/master/api.md
It looks ok, what version are you using and did it install correctly. Maybe delete node_modules folder and execute npm install and try again
import { useRender } from 'react-three-fiber'
import { Canvas } from 'react-three-fiber'
install > @react-three/fiber and then change 'useRender' for 'useFrame'; it should work but be careful with this! you should get information from official documentation! ---> https://github./pmndrs/react-three-fiber
import React, { useState, useRef } from "react";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls";
import { Canvas, extend, useThree, useFrame } from "@react-three/fiber";
extend({ OrbitControls });
const Controls = () => {
const orbitRef = useRef();
const { camera, gl } = useThree();
useFrame(() => {
orbitRef.current.update();
});
return <orbitControls args={[camera, gl.domElement]} ref={orbitRef} />;
};
const Box = () => {
const [hoverd, setHoverd] = useState(false);
return (
<mesh
onPointerOver={() => setHoverd(true)}
onPointerOut={() => setHoverd(false)}
>
<boxBufferGeometry attach="geometry" args={[2, 2, 2]} />
<meshBasicMaterial
attach="material"
color={hoverd ? "hotpink" : "gray"}
/>
</mesh>
);
};
const Box = () => {
return (
<Canvas>
<Controls />
<Box />
</Canvas>
);
};
export default Box;
本文标签: javascriptReactthreefiber 39useRender39 is not exported from 39reactthreefiber39Stack Overflow
版权声明:本文标题:javascript - React-three-fiber 'useRender' is not exported from 'react-three-fiber' - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745633010a2667386.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论