Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/hooks/useConfirmModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const useConfirmModal = () => {
const showConfirmModal = (options: ConfirmModalOptions) => {
return context.showModal({
component: ConfirmModalWrapper,
props: options,
props: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-4 (docs)

Creating a new object literal on every showConfirmModal call causes unnecessary re-renders. The spread operator ...options combined with the wrapping object creates a new object reference each time, preventing React from optimizing renders.

Suggested fix:

const showConfirmModal = useCallback((options: ConfirmModalOptions) => {
    return context.showModal({
        component: ConfirmModalWrapper,
        props: {
            shouldHandleNavigationBack: true,
            ...options,
        },
    });
}, [context]);

Or if shouldHandleNavigationBack should be overridable:

const showConfirmModal = useCallback((options: ConfirmModalOptions) => {
    return context.showModal({
        component: ConfirmModalWrapper,
        props: {
            ...options,
            shouldHandleNavigationBack: options.shouldHandleNavigationBack ?? true,
        },
    });
}, [context]);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this hook is correctly compiled by React Compiler, so this should be safe to ignore

shouldHandleNavigationBack: true,
...options,
},
});
};

Expand Down
Loading