| 1 |
import { useEffect } from "@wordpress/element"; |
| 2 |
import { useSelect, useDispatch } from "@wordpress/data"; |
| 3 |
import { store as blockEditorStore } from "@wordpress/block-editor"; |
| 4 |
|
| 5 |
const useUpdateParentAttributes = (clientId, data) => { |
| 6 |
|
| 7 |
const { updateBlockAttributes } = useDispatch(blockEditorStore); |
| 8 |
|
| 9 |
// Get parent block id |
| 10 |
const parentId = useSelect((select) => { |
| 11 |
return select(blockEditorStore).getBlockRootClientId(clientId); |
| 12 |
}, [clientId]); |
| 13 |
|
| 14 |
useEffect(() => { |
| 15 |
|
| 16 |
if (parentId) { |
| 17 |
updateBlockAttributes(parentId, { |
| 18 |
multipleFilterRelation: data, |
| 19 |
}); |
| 20 |
} |
| 21 |
|
| 22 |
}, [data, parentId]); |
| 23 |
|
| 24 |
}; |
| 25 |
|
| 26 |
export default useUpdateParentAttributes; |