feat(utils/nui): able to merge data

This commit is contained in:
Christopher committed 2021-01-28 00:41:15 +01:00
1 parent d3a2ee7628
commit 804c8da9cb
1 file changed
+4 -2
+4 -2
View File
@@ -20,7 +20,8 @@ export const useNuiEvent = (
app: string, app: string,
method: string, method: string,
handler: Function, handler: Function,
options: IOptions = {} options: IOptions = {},
currentState?: Record<string, unknown>
) => { ) => {
const savedHandler: MutableRefObject<any> = useRef(); const savedHandler: MutableRefObject<any> = useRef();
// Destructure passed options // Destructure passed options
@@ -42,7 +43,8 @@ export const useNuiEvent = (
data: event.data, data: event.data,
level: 1, level: 1,
}); });
savedHandler.current(data); const newData = currentState ? { ...currentState, ...data } : data
savedHandler.current(newData)
} }
}; };
// Why are destructing then restructuring option data? // Why are destructing then restructuring option data?