debounce reloading event list

This commit is contained in:
Daniel Waxweiler 2022-06-09 19:46:59 +02:00
parent 55fcf4c756
commit c1ee30b070
1 changed files with 7 additions and 2 deletions

View File

@ -8,6 +8,8 @@ const { __ } = wp.i18n
const NAME = '<wordpress-name>'
let timer
export default ({ attributes, setAttributes }) => {
const blockProps = useBlockProps({
className: NAME + '_events-list',
@ -15,12 +17,15 @@ export default ({ attributes, setAttributes }) => {
'data-group-name': attributes.groupName,
})
function reloadEventList() {
setTimeout(() => {
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
const container = document.getElementById(blockProps.id)
if (container) {
loadEventList(container)
}
}, 0)
}, 500)
}
useEffect(() => {
reloadEventList()