Struggling to think of the best way to go about it. I can use a recursive call with requestAnimationFrame to have a game loop:
export interface Props {
name: string;
points: number;
onIncrement?: () => void;
onDecrement?: () => void;
}
class Hello extends React.Component<Props, object> {
constructor(props: Props) {
super(props);
}
render() {
const { name, points, onIncrement, onDecrement } = this.props;
return (
<div className="hello">
<div className="greeting">
Hello {name + points}
</div>
<button onClick={onDecrement}>-</button>
<button onClick={onIncrement}>+</button>
</div>
);
}
componentDidMount() {
this.tick();
}
tick = () => {
this.props.onIncrement();
requestAnimationFrame(this.tick)
}
}
But what if I want on each frame:
- Component1 to do X
- Component2 to do Y
- Component3 to do Z
I could just have another loop in each component, however my understanding is it is bad practice to have multiple requestAnimationFrame loops going and it is a significant performance hit.
So I'm at a lost here. How can I have another component use the same loop? (If that even is the best way to go about it!)
