Hello,
I copied code from documentation:
import { RpgReactContext } from '@rpgjs/client/react';
import { useContext, useEffect, useState } from 'react';
export default function InventoryGUI() {
const { rpgCurrentPlayer } = useContext(RpgReactContext);
const [hp, setHp] = useState(0);
useEffect(() => {
rpgCurrentPlayer.subscribe(({ object }) => {
setHp(object.hp);
});
return () => {
rpgCurrentPlayer.unsubscribe();
};
}, []);
return (
<div style={{ marginLeft: '500px' }}>
<h1>HP IS = {hp}</h1>
</div>
);
}
and I am getting such an error:
Uncaught TypeError: rpgCurrentPlayer.unsubscribe is not a function
at InventoryGUI.tsx:16:26
at safelyCallDestroy (react-dom.development.js:22932:5)
at commitHookEffectListUnmount (react-dom.development.js:23100:11)
at commitPassiveUnmountInsideDeletedTreeOnFiber (react-dom.development.js:25098:11)
at commitPassiveUnmountEffectsInsideOfDeletedTree_begin (react-dom.development.js:25048:5)
at commitPassiveUnmountEffects_begin (react-dom.development.js:24956:11)
at commitPassiveUnmountEffects (react-dom.development.js:24941:3)
at flushPassiveEffectsImpl (react-dom.development.js:27038:3)
at flushPassiveEffects (react-dom.development.js:26984:14)
at react-dom.development.js:26769:9
This issue occurs when I close the GUI:
import { RpgPlayer, RpgPlayerHooks } from "@rpgjs/server";
const player: RpgPlayerHooks = {
onJoinMap(player: RpgPlayer) {
player.gui('inventory-gui').open();
setTimeout(() => {
player.gui('inventory-gui').close();
}, 5000);
}
}
export default player;