Maintains and determines the current state of the active tab.

useActiveTab(initialTabName: string, tabs: Array): Array
Since: 1.3.0
Parameters
initialTabName (string) Initial tab element to be selected upon mounting of component.
tabs (Array) Tabs stored from the previous state.
Returns
Array: Returns a stateful value, and a function to update it.
Example
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.

useColumnsProps(props: Object): Object
Since: 1.8.0
Parameters
props (Object) An object of breakpoints for columns and viewport-wide gap (gutter) value.
Returns
Object: Returns an object of CSS class names and inline style object.
Example
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.

useConditionalRef(isSave: boolean, initialValue: any): Object
Since: 1.3.0
Parameters
isSave (boolean = false) Whether the field is meant to be rendered on the front-end.
initialValue (any) Initial value used during the initial render.
Returns
Object: Returns a mutable ref object whose .current property is initialized to the passed argument.
Example
const anchorRef = useConditionalRef( isSave );

This hook mimicks the componentDidMount hook for React.

useDidMount(callback: Function): void
Since: 1.0.0
Parameters
callback (Function) Function to be called when component is mounted.
Returns
void:
Example
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.

useDidUpdate(callback: Function, conditions: Array): void
Since: 1.1.0
Parameters
callback (Function) Function to be called when component is updated.
conditions (Array = []) The list of variables which trigger update when they are changed.
Returns
void:
Example
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.

useFindPostById(postId: number, postsQuery: Array): (null | Object)
Since: 1.5.0
Parameters
postId (number) Selected post id.
postsQuery (Array) List of posts retrieved from the API query.
Returns
(null | Object): Post object.
Example
const post = useFindPostById( postId, postsQuery );

Retrives the block support value for the "Layout" settings to be used in the preview.

useGetBlockLayout(blockTypeOrName: string): Object
Since: 1.11.0
Parameters
blockTypeOrName (string) The name for a block is a unique string that identifies a block.
Returns
Object: Block level "Layout" settings object.
Example
const { default } = useGetBlockLayout( 'core/social-links' );

// { 'type': 'flex' }

Retrieves the current post object given the post ID and post-type.

useGetCurrentPost(postId: number, postType: string): Object
Since: 1.12.0
Parameters
postId (number) Post ID.
postType (string) Post-type name (key).
Returns
Object: Returns the post object.
Example
const currentPost = useGetCurrentPost( 748, 'page' );

Retrieve media MIME type based on given attachment id.

useGetMediaType(id: number): string
Since: 1.10.0
Parameters
id (number) Attachment ID.
Returns
string: Retrieve media type associated with the given attachment ID known as MIME type.
Example
const backgroundType = useGetMediaType( id );

Generates custom (notification) toast messages.

useToast(): Function
Since: 1.2.1
Returns
Function: A function that could be called to initiate toast messages.
Example
const toast = useToast();
toast( 'Text to display as a toast message!' );

Retrieve list of HTML nodes genearted for each post item.

useGetNodeList(endpoint: string, args: Object, predicate: Function): Array
Since: 1.14.0
Parameters
endpoint (string) API node endpoint.
args (Object = {}) Arguments to be passed to the apiFetch method.
predicate (Function = identity) The function invoked per property. The predicate is invoked with two arguments: (value, key).
Returns
Array: List of HTML nodes to be referred to when each post item looped over.
Example
const nodeList = useGetNodeList( 'sixa-recent-posts-block/v1/nodes' );

Retrieves a post meta field of the current post.

useGetPostMeta(metaKey: string): Object
Since: 1.7.0
Parameters
metaKey (string) The meta key to retrieve.
Returns
Object: An object containing currently viewed post-id and meta field value.
Example
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.

useGetPosts(args: Object, clientId: string, postType: string): Object
Since: 1.6.2
Parameters
args (Object = {}) Arguments to be passed to the apiFetch method.
clientId (string) The block’s client id.
postType (string) Post type name.
Returns
Object: List of posts retrieved from the API along with a list of options to select from.
Example
const { postsOptions, postsQuery } = useGetPosts( { order: 'asc' }, clientId, 'posts' );

This hook takes a parameter with value and allows for quickly toggling the value.

useToggle(initialValue: (any | boolean), toggleFunction: Function): Array
Since: 1.1.0
Parameters
initialValue ((any | boolean) = false) Initial value of the toggle.
toggleFunction (Function) A toggle function. This allows for non boolean toggles.
Returns
Array: Returns a stateful value, and a function to update it.
Example
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.

useGetProducts(args: Object, clientId: string): Object
Since: 1.4.0
Parameters
args (Object = {}) Arguments to be passed to the apiFetch method.
clientId (string) The block’s client id.
Returns
Object: List of posts retrieved from the API along with a list of options to select from.
Example
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.

useGetProductTerms(taxonomy: string, args: Object): Object
Since: 1.4.1
Parameters
taxonomy (string) Taxonomy name.
args (Object = {}) Arguments to be passed to the apiFetch method.
Returns
Object: List of terms retrieved from the API along with a list of options to select from.
Example
const { termsOptions, termsQuery } = useGetProductTerms( 'categories' );

Retrieves the current site data or object.

useGetSiteData(dependencies: Array): Object
Since: 1.12.0
Parameters
dependencies (Array = []) An array of optional dependencies to refresh the hook output.
Returns
Object: Returns site data and title within an object.
Example
const { siteTitle } = useGetSiteData();

Retrieve list of taxonomy terms and maintain refreshing this list when any of the direct arguments changed.

useGetTerms(taxonomy: string, args: Object): Object
Since: 1.6.2
Parameters
taxonomy (string) Taxonomy name.
args (Object = {}) Arguments to be passed to the apiFetch method.
Returns
Object: List of terms retrieved from the API along with a list of options to select from.
Example
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.

useInnerBlocksProps
Since: 1.9.2
Example
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.

useInputValue(initialValue: string): Array
Since: 1.1.0
Parameters
initialValue (string = '') Initial value of the field.
Returns
Array: Returns a stateful value, and a function to update it.
Example
const [ value, setValue ] = useInputValue( 'Hello' );
<TextControl onChange={ setValue } value={ value } />

This hook determines whether an element is being dragged within another (ref) target element.

useIsDraggingWithin(elementRef: Object): boolean
Since: 1.13.0
Parameters
elementRef (Object) A mutable ref element object whose .current property is initialized to the passed argument.
Returns
boolean: Is dragging within the target element.
Example
const listItemRef = useRef( null );
const isDraggingWithin = useIsDraggingWithin( listItemRef );

Get latitude & longitude from address.

useLatLngBounds(address: string, apiKey: string, locale: string): (Object | string)
Since: 1.3.0
Parameters
address (string = '') Address.
apiKey (string = '') GoogleMaps API key.
locale (string = 'en') Region and language code of the parsed address.
Returns
(Object | string): latitude & longitude object or error message.
Example
const latLng = useLatLngBounds( 'Skyland Istanbul, Sarıyer, Turkey', 'H7ZH7p3dHa24...', 'en );

Validate and normalize JSON string to an array.

useNormalizeJsonify(value: string): Array
Since: 1.5.0
Parameters
value (string = '[""]') JSON string to be normalized to an array.
Returns
Array: Constructed JavaScript object from the given JSON string.
Example
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.

usePostTypeNameRestBase(postType: string): Object
Since: 1.9.0
Parameters
postType (string) Post type name and rest-base key.
Returns
Object: Object of post-type name and REST-API base key.
Example
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.

usePreparePosts(ids: Array, limit: number, query: Array): Object
Since: 1.2.0
Parameters
ids (Array = []) Handpicked post ids.
limit (number = 3) Maximum number of posts to show.
query (Array) List of posts retrieved from the API query.
Returns
Object: Sliced query, maximum number of available posts, and whether there are posts to loop over.
Example
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.

useTimeout(callback: Function, timeoutDelayMs: number): Object
Since: 1.1.0
Parameters
callback (Function) The callback to be invoked after timeout.
timeoutDelayMs (number = 1000) Amount of time in ms after which to invoke.
Returns
Object: Current state of the timer and methods to start and stop the timer.
Example
const [ isBusy, toggleIsBusy ] = useToggle( true );
const { start } = useTimeout( toggleIsBusy, 2000 );
start();

Updates a post meta field based on the given post ID.

useUpdatePostMeta(metaKey: string, metaValue: string, postId: number, postType: string): Function
Since: 1.7.0
Parameters
metaKey (string) The meta key to retrieve.
metaValue (string = {}) Metadata value.
postId (number) Post ID.
postType (string) Post type key/name.
Returns
Function: A callback function invoked when the component requires update post-meta data.
Example
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.

useVisibilityClassNames(viewports: Object): Array
Since: 1.6.3
Parameters
viewports (Object) An object of breakpoints with their state of visibility being defined.
Returns
Array: Returns a list of visibility CSS class names.
Example
const classNames = useVisibilityClassNames( { laptop: true, tablet: true, mobile: false } );

// => Array [ 'sixa-hide-laptop', 'sixa-hide-tablet' ]