Skip to content

Instantly share code, notes, and snippets.

@ilhamgusti
Created February 10, 2021 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilhamgusti/9d1dd9980c91ac4a39f52ef97287b7b6 to your computer and use it in GitHub Desktop.
Save ilhamgusti/9d1dd9980c91ac4a39f52ef97287b7b6 to your computer and use it in GitHub Desktop.
use modal with data
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