Skip to main content

JS

Existing JS utilities that might be useful for development.

Debounce()

Debounce is a utility that will prevent a function from running multiple times in a row. This is useful for functions that are triggered by scroll or resize events.

Usage:

import debounce from './utilities/debounce'; // Make sure the import path is correct for your component

window.addEventListener('scroll', Debounce(() => {
// Do something
}, 100));

editorIsReady()

This utility will check to see if the Gutenberg editor is ready. This function returns a promise.

Usage:

import editorIsReady from './utilities/editorIsReady'; // Make sure the import path is correct for your component

editorIsReady().then( () => {
// Do something
} );

isMotionOk()

This utility will check to see if the user has requested reduced motion in their OS settings. This function returns a boolean.

Usage:

import isMotionOk from './utilities/isMotionOk'; // Make sure the import path is correct for your component

if ( isMotionOk() ) {
// Run the animation
}