1.14.0
Maintains and determines the current state of the active tab.
(string)
Initial tab element to be selected upon mounting of component.
(Array)
Tabs stored from the previous state.
Array
:
Returns a stateful value, and a function to update it.
const [ activeTab, setActiveTab ] = useActiveTab( initialTabName, tabs );
This hook maintains the state of each Columns viewport and returns a list of Columns (breakpoint) CSS class names along with inline CSS style for the gap range defined viewport-wide.
(Object)
An object of breakpoints for columns and viewport-wide gap (gutter) value.
Object
:
Returns an object of CSS class names and inline style object.
const { className, style } = useColumnsProps( { columns: { widescreen: 4, laptop: 4, tablet: 2, mobile: 1 }, gap: '0px' } );
// className => Array [ 'sixa-columns-5-widescreen', 'sixa-columns-4-laptop', 'sixa-columns-2-tablet', 'sixa-columns-1-mobile' ]
// style => Object { '--columns-gap': '20px' }
Conditionally return an instance of useRef
.
(boolean
= false
)
Whether the field is meant to be rendered on the front-end.
(any)
Initial value used during the initial render.
Object
:
Returns a mutable ref object whose
.current
property is initialized to the passed argument.
const anchorRef = useConditionalRef( isSave );
This hook mimicks the componentDidMount
hook for React.
(Function)
Function to be called when component is mounted.
void
:
useDidMount( () => {
console.log( 'Mounted!' );
} );
This hook mimicks the componentDidUpdate
hook for React.
Fires a callback on component update, and can take in a list of
conditions to fire callback when one of the conditions changes.
(Function)
Function to be called when component is updated.
(Array
= []
)
The list of variables which trigger update when they are changed.
void
:
useDidUpdate( () => {
console.log( 'Updated!' );
}, [ var1, var2 ] );
Finds the selected post object based on the given post id and maintains the state of change when it happens.
(null | Object)
:
Post object.
const post = useFindPostById( postId, postsQuery );
Retrives the block support value for the "Layout" settings to be used in the preview.
(string)
The name for a block is a unique string that identifies a block.
Object
:
Block level "Layout" settings object.
const { default } = useGetBlockLayout( 'core/social-links' );
// { 'type': 'flex' }
Retrieves the current post object given the post ID and post-type.
Object
:
Returns the post object.
const currentPost = useGetCurrentPost( 748, 'page' );
Retrieve media MIME type based on given attachment id.
(number)
Attachment ID.
string
:
Retrieve media type associated with the given attachment ID known as MIME type.
const backgroundType = useGetMediaType( id );
Generates custom (notification) toast messages.
Function
:
A function that could be called to initiate toast messages.
const toast = useToast();
toast( 'Text to display as a toast message!' );
Retrieve list of HTML nodes genearted for each post item.
(string)
API node endpoint.
(Object
= {}
)
Arguments to be passed to the apiFetch method.
(Function
= identity
)
The function invoked per property. The predicate is invoked with two arguments: (value, key).
Array
:
List of HTML nodes to be referred to when each post item looped over.
const nodeList = useGetNodeList( 'sixa-recent-posts-block/v1/nodes' );
Retrieves a post meta field of the current post.
(string)
The meta key to retrieve.
Object
:
An object containing currently viewed post-id and meta field value.
const { metaValue, postId, postSlug } = useGetPostMeta( 'sixa_blocks_theme_meta' );
Retrieve list of post-type posts and maintain refreshing this list when any of the direct arguments changed.
(Object
= {}
)
Arguments to be passed to the apiFetch method.
(string)
The block’s client id.
(string)
Post type name.
Object
:
List of posts retrieved from the API along with a list of options to select from.
const { postsOptions, postsQuery } = useGetPosts( { order: 'asc' }, clientId, 'posts' );
This hook takes a parameter with value and allows for quickly toggling the value.
((any | boolean)
= false
)
Initial value of the toggle.
(Function)
A toggle function. This allows for non boolean toggles.
Array
:
Returns a stateful value, and a function to update it.
const [ value1, toggleValue1 ] = useToggle();
const [ value2, toggleValue2 ] = useToggle( true );
const [ value3, toggleValue3 ] = useToggle( 'start', customToggleFunction );
Retrieve list of product posts and maintain refreshing this list when any of the direct arguments changed.
(Object
= {}
)
Arguments to be passed to the apiFetch method.
(string)
The block’s client id.
Object
:
List of posts retrieved from the API along with a list of options to select from.
const { productsOptions, productsQuery } = useGetProducts( { order: 'asc' }, clientId );
Retrieve list of product taxonomy terms and maintain refreshing this list when any of the direct arguments changed.
Object
:
List of terms retrieved from the API along with a list of options to select from.
const { termsOptions, termsQuery } = useGetProductTerms( 'categories' );
Retrieves the current site data or object.
(Array
= []
)
An array of optional dependencies to refresh the hook output.
Object
:
Returns site data and title within an object.
const { siteTitle } = useGetSiteData();
Retrieve list of taxonomy terms and maintain refreshing this list when any of the direct arguments changed.
Object
:
List of terms retrieved from the API along with a list of options to select from.
const { termsOptions, termsQuery } = useGetTerms( 'categories' );
This module merely adds backward compatibility for the usage of experimental
useInnerBlocksProps
in projects created using WordPress versions prior to 5.9.
const blockProps = useBlockProps( { className: 'my-class' } );
const innerBlocksProps = useInnerBlocksProps(
blockProps,
{ allowedBlocks: [ 'core/heading', 'core/paragraph', 'core/image' ] }
);
This hook takes an initial value for an input field
and updates it when the onChange
event raises.
(string
= ''
)
Initial value of the field.
Array
:
Returns a stateful value, and a function to update it.
const [ value, setValue ] = useInputValue( 'Hello' );
<TextControl onChange={ setValue } value={ value } />
This hook determines whether an element is being dragged within another (ref) target element.
(Object)
A mutable ref element object whose
.current
property is initialized to the passed argument.
boolean
:
Is dragging within the target element.
const listItemRef = useRef( null );
const isDraggingWithin = useIsDraggingWithin( listItemRef );
Get latitude & longitude from address.
(string
= ''
)
Address.
(string
= ''
)
GoogleMaps API key.
(string
= 'en'
)
Region and language code of the parsed address.
(Object | string)
:
latitude & longitude object or error message.
const latLng = useLatLngBounds( 'Skyland Istanbul, Sarıyer, Turkey', 'H7ZH7p3dHa24...', 'en );
Validate and normalize JSON string to an array.
(string
= '[""]'
)
JSON string to be normalized to an array.
Array
:
Constructed JavaScript object from the given JSON string.
const options = useNormalizeJsonify( '[\u0022Search Engine\u0022,\u0022Social Media\u0022]' );
// => Array [ 'Search Engine', 'Social Media' ]
This hook maintains the state of post-type name and REST-API base key extraction from the given string value.
(string)
Post type name and rest-base key.
Object
:
Object of post-type name and REST-API base key.
const { postTypeKey, restBaseKey } = usePostTypeNameRestBase( 'post|posts' );
Determines whether the current WordPress query has posts to loop over, and slices the query according to the maximum limit determined.
(Array
= []
)
Handpicked post ids.
(number
= 3
)
Maximum number of posts to show.
(Array)
List of posts retrieved from the API query.
Object
:
Sliced query, maximum number of available posts, and whether there are posts to loop over.
const { havePosts, maxLimit, slicedQuery } = usePreparePosts( [2], 3, [ { id: 1, title: 'Post A' }, { id: 2, title: 'Post B' } ] );
A setTimeout hook that calls a callback after a timeout duration.
(Function)
The callback to be invoked after timeout.
(number
= 1000
)
Amount of time in ms after which to invoke.
Object
:
Current state of the timer and methods to start and stop the timer.
const [ isBusy, toggleIsBusy ] = useToggle( true );
const { start } = useTimeout( toggleIsBusy, 2000 );
start();
Updates a post meta field based on the given post ID.
(string)
The meta key to retrieve.
(string
= {}
)
Metadata value.
(number)
Post ID.
(string)
Post type key/name.
Function
:
A callback function invoked when the component requires update post-meta data.
const setMeta = useUpdatePostMeta( 'sixa_blocks_theme_meta', { title: false }, 8, 'post' );
This hook maintains the state of each visibility viewport and returns a list of visibility (breakpoint) CSS class names.
(Object)
An object of breakpoints with their state of visibility being defined.
Array
:
Returns a list of visibility CSS class names.
const classNames = useVisibilityClassNames( { laptop: true, tablet: true, mobile: false } );
// => Array [ 'sixa-hide-laptop', 'sixa-hide-tablet' ]