Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在react three fiber中使用外部数据和useFrame的最佳方法_Javascript_Reactjs_React Three Fiber - Fatal编程技术网

Javascript 在react three fiber中使用外部数据和useFrame的最佳方法

Javascript 在react three fiber中使用外部数据和useFrame的最佳方法,javascript,reactjs,react-three-fiber,Javascript,Reactjs,React Three Fiber,我有一个名为Sticky的组件,它包裹了我的react三个光纤组件。此组件通过回调为我提供一些状态更新,因此整个代码如下所示: const Box = props => { useFrame(() => { // I need the Sticky state update here! }); return ( <mesh {...props}> <boxBufferGeometry attach="geom

我有一个名为
Sticky
的组件,它包裹了我的
react三个光纤组件。此组件通过回调为我提供一些状态更新,因此整个代码如下所示:

const Box = props => {
  
  useFrame(() => {
    // I need the Sticky state update here!
  });

  return (
    <mesh {...props}>
      <boxBufferGeometry attach="geometry" args={[1, 1, 1]} />
      <meshStandardMaterial
        attach="material"
        color={"orange"}
      />
    </mesh>
  );
};

const Main = () => {
  const onChange = state => {
    console.log('NEW STATE', state);
  };

  return (
    <Sticky onChange={onChange}
        <Canvas>
          <Box position={[-1.2, 0, 0]} />
        </Canvas>
    </Sticky>
  );
};
const-Box=props=>{
useFrame(()=>{
//我需要粘性状态更新在这里!
});
返回(
);
};
常量Main=()=>{
const onChange=state=>{
console.log('newstate',STATE);
};
返回(