feat: multiplayer undo / redo (#7348)

This commit is contained in:
Marcel Mraz 2024-04-17 13:01:24 +01:00 committed by GitHub
parent 5211b003b8
commit 530617be90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
71 changed files with 34885 additions and 14877 deletions

View file

@ -0,0 +1,21 @@
import { useEffect, useState } from "react";
import { Emitter } from "../emitter";
export const useEmitter = <TEvent extends unknown>(
emitter: Emitter<[TEvent]>,
initialState: TEvent,
) => {
const [event, setEvent] = useState<TEvent>(initialState);
useEffect(() => {
const unsubscribe = emitter.on((event) => {
setEvent(event);
});
return () => {
unsubscribe();
};
}, [emitter]);
return event;
};