Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 47x 47x 4x 4x 47x | /**
* External dependencies
*/
import { useStagedSearch } from '@jetpack-premium-analytics/routing';
import { useCallback } from '@wordpress/element';
type SectionSearch = {
section?: string;
};
/**
* Read and update the active section via the `?section=` search param, the dashboard's
* deep-linkable model. Switching stages and commits at once: one history entry per change,
* unless `replace` is set to normalize a deep link.
*
* @param routeFrom - The path of the route the page is mounted on.
* @return The section the URL names, and a setter.
*/
export function useActiveSection(
routeFrom: string
): [ string | undefined, ( slug: string, options?: { replace?: boolean } ) => void ] {
const { effective, stage, commit } = useStagedSearch< SectionSearch, string >( {
from: routeFrom,
} );
const setActiveSection = useCallback(
( slug: string, options?: { replace?: boolean } ) => {
stage( { section: slug } );
commit( { replace: options?.replace ?? false } );
},
[ stage, commit ]
);
return [ effective.section, setActiveSection ];
}
|