useOnUpdateModal.js
23 lines
| 1 | import ActionModalContext from '../context/ActionModalContext'; |
| 2 | |
| 3 | const { |
| 4 | useContext, |
| 5 | useEffect, |
| 6 | } = wp.element; |
| 7 | |
| 8 | function useOnUpdateModal( callback ) { |
| 9 | const { actionClick, onRequestClose } = useContext( ActionModalContext ); |
| 10 | |
| 11 | useEffect( () => { |
| 12 | // update field attributes |
| 13 | if ( actionClick ) { |
| 14 | callback(); |
| 15 | } |
| 16 | |
| 17 | if ( null !== actionClick ) { |
| 18 | onRequestClose(); |
| 19 | } |
| 20 | }, [ actionClick ] ); |
| 21 | } |
| 22 | |
| 23 | export default useOnUpdateModal; |