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);
};
返回(