Created
October 6, 2021 05:30
-
-
Save artygrand/ab836128f241b7886740638be7a82e90 to your computer and use it in GitHub Desktop.
Wrap react's setState with callback or mutator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const wrappedSetInvoice = useCallback((value: ((i: InvoiceModel) => InvoiceModel) | InvoiceModel) => { | |
setInvoice(old => { | |
const updated = value instanceof Function ? value(old) : value; | |
return {...updated, dirty: true}; | |
}); | |
}, [setInvoice]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment