Created
February 10, 2021 02:33
-
-
Save ilhamgusti/9d1dd9980c91ac4a39f52ef97287b7b6 to your computer and use it in GitHub Desktop.
use modal with data
This file contains hidden or 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
import React from 'react'; | |
export const useModal = () => { | |
const [data, setData] = React.useState({}); | |
const [activeModal, setActiveModal] = React.useState(''); | |
const handleModalOpen = React.useCallback( | |
({ type, index, dataSource }) => (e) => { | |
setData(dataSource); | |
setActiveModal(type); | |
}, | |
[] | |
); | |
const handleModalClose = React.useCallback(() => { | |
setData({}); | |
setActiveModal(''); | |
}, []); | |
return { data, handleModalOpen, handleModalClose, activeModal }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment