pixi-fusion
Version:
This module offers a set of common components needed for playing games.
18 lines (17 loc) • 503 B
JavaScript
import { useContext, useEffect } from "react";
import { MatterPhysicsContext } from "../physics";
export const usePhysicalObject = ({ physicalObject }) => {
const { addBody, removeBody } = useContext(MatterPhysicsContext);
useEffect(() => {
if (!physicalObject) {
return () => { };
}
addBody(physicalObject);
return () => {
removeBody(physicalObject);
};
}, [physicalObject?.id]);
return {
physicalObject
};
};