From dd7be865ad0492c40cf8aa0c5ee9eb5d71c17994 Mon Sep 17 00:00:00 2001 From: Rohitbels Date: Thu, 28 Mar 2024 13:18:02 +0530 Subject: [PATCH] Shallow copying the entire object to copy owned as well as prototype properties https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptors#:~:text=Whereas%20the%20Object.assign()%20method%20will%20only%20copy%20enumerable%20and%20own%20properties%20from%20a%20source%20object%20to%20a%20target%20object%2C%20you%20are%20able%20to%20use%20this%20method%20and%20Object.create()%20for%20a%20shallow%20copy%20between%20two%20unknown%20objects%3A --- packages/sortable/src/hooks/useSortable.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/sortable/src/hooks/useSortable.ts b/packages/sortable/src/hooks/useSortable.ts index 6560b8a6..789a5d43 100644 --- a/packages/sortable/src/hooks/useSortable.ts +++ b/packages/sortable/src/hooks/useSortable.ts @@ -64,7 +64,11 @@ export function useSortable({ ); const index = items.indexOf(id); const data = useMemo( - () => ({sortable: {containerId, index, items}, ...customData}), + () => ({sortable: {containerId, index, items}, + ...Object.create( + Object.getPrototypeOf(customData), + Object.getOwnPropertyDescriptors(customData), + )}), [containerId, customData, index, items] ); const itemsAfterCurrentSortable = useMemo(