Skip to content

Swipeable - How to prevent auto closing after executing onSwipeableOpen #2464

Closed Answered by krystianlaubach
krystianlaubach asked this question in Q&A
Discussion options

You must be logged in to vote

After small break to refresh my brain and then couple of hours further digging I found the root cause and the solution.

Swipeable component actually has not been getting closed after onSwipeableOpen execution. It looked like it's been getting closed as the component was re-rendered after updating selectedInvoices state.

It's because I've been using useState hook, then updating state is always causing re-render.

    const [selectedInvoices, setSelectedInvoices] = useState<Array<number>>([]);

    const selectInvoice = (invoiceNumber: number): void => {
        setSelectedInvoices((currentSelectedInvoices: Array<number>) => [...currentSelectedInvoices, invoiceNumber]);
    };

    const uns…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by krystianlaubach
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant