How to use the @wordpress/element.useState function in @wordpress/element

To help you get started, we’ve selected a few @wordpress/element examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github php4dev / heroku-wordpress / wp-content / plugins / woocommerce / packages / woocommerce-blocks / assets / js / base / hooks / use-collection-data.js View on Github external
useEffect( () => {
		if (
			calculatePriceRangeQueryState !== currentQueryPrices &&
			currentQueryPrices !== undefined
		) {
			setCalculatePriceRangeQueryState( currentQueryPrices );
		}
	}, [
		currentQueryPrices,
		setCalculatePriceRangeQueryState,
		calculatePriceRangeQueryState,
	] );

	// Defer the select query so all collection-data query vars can be gathered.
	const [ shouldSelect, setShouldSelect ] = useState( false );
	const [ debouncedShouldSelect ] = useDebounce( shouldSelect, 200 );

	if ( ! shouldSelect ) {
		setShouldSelect( true );
	}

	const collectionDataQueryVars = useMemo( () => {
		return buildCollectionDataQuery( collectionDataQueryState );
	}, [ collectionDataQueryState ] );

	return useCollection( {
		namespace: '/wc/store',
		resourceName: 'products/collection-data',
		query: {
			...queryState,
			page: undefined,
github gambitph / Stackable / src / block / icon / edit.js View on Github external
className,
		setAttributes,
		attributes,
		isSelected,
	} = props

	const {
		design = 'basic',
		columns = 1,
		showTitle = false,
		titleTop = false,
		titleTag = '',
	} = props.attributes

	const [ selected, setSelected ] = useState( false )
	const [ urlPopupPosition, setUrlPopupPosition ] = useState( 'bottom center' )
	const [ refreshPositionInterval, setRefreshPositionInterval ] = useState( null )

	const show = showOptions( props )

	const mainClasses = classnames( [
		className,
		`ugb-icon--design-${ design }`,
	], applyFilters( 'stackable.icon.mainclasses', {
	}, props ) )

	// Updates the position of the url popup to be opposite of the icon popup.
	const refreshPosition = () => {
		const popover = document.querySelector( '.ugb-icon-popover' )
		if ( popover ) {
			if ( popover.classList.contains( 'is-from-top' ) ) {
				setUrlPopupPosition( 'top center' )
github Automattic / vip-go-mu-plugins-built / jetpack / extensions / shared / external-media / sources / google-photos / filter-option.js View on Github external
function DateOption( { value, updateFilter } ) {
	const selectedRange = value?.range || DATE_RANGE_ANY;

	const [ month, setMonth ] = useState( -1 );
	const [ year, setYear ] = useState( CURRENT_YEAR );

	return (
		<div>
			 updateFilter( { range } ) }
			/&gt;
			{ selectedRange === DATE_RANGE_CUSTOM &amp;&amp; (
				
					</div>
github dsifford / academic-bloggers-toolkit / src / js / gutenberg / dialogs / add-reference / dialog.tsx View on Github external
function Dialog({ onClose, onSubmit }: Props) {
    const { createErrorNotice } = useDispatch('core/notices');
    const [isAddingManually, setIsAddingManually] = useState(false);
    const [isBusy, setIsBusy] = useState(false);

    const FORM_ID = 'add-reference-form';

    return (
        &lt;&gt;
            {!isAddingManually &amp;&amp; (
                 setIsBusy(busy)}
                    onClose={onClose}
                    onError={message =&gt;
                        createErrorNotice(message, { type: 'snackbar' })
                    }
                    onSubmit={onSubmit}
                /&gt;
            )}
github ampproject / amp-wp / assets / src / edit-story / components / switch / index.js View on Github external
function Switch( { label, checked, onChange } ) {
	const [ on, setOn ] = useState( checked );
	const handleChange = ( evt ) =&gt; {
		setOn( evt.target.checked );
		if ( onChange ) {
			onChange( evt.target.checked );
		}
	};
	useEffect( () =&gt; setOn( checked ), [ checked ] );
	return (
		
			<label>
				{ label }
			</label>
github ampproject / amp-wp / assets / src / stories-editor / components / context-menu / index.js View on Github external
const ContextMenu = ( props ) => {
	const {
		clientIds,
		clientX,
		clientY,
		insidePercentageX,
		insidePercentageY,
	} = props;
	const [ isOpen, setIsOpen ] = useState( true );

	const {
		getBlock,
		getBlockOrder,
		getBlockRootClientId,
		getSettings,
	} = useSelect( ( select ) => select( 'core/block-editor' ), [] );

	const {
		getCopiedMarkup,
		getCurrentPage,
	} = useSelect( ( select ) => select( 'amp/story' ), [] );

	const {
		removeBlock,
		insertBlock,
github WordPress / gutenberg / packages / block-editor / src / components / page-template-picker / preview.native.js View on Github external
const useScreenDimensions = ( dimension = 'window' ) => {
	const [ dimensions, setDimensions ] = useState( Dimensions.get( dimension ) );

	useEffect( () => {
		const onChange = ( result ) => {
			setDimensions( result[ dimension ] );
		};

		Dimensions.addEventListener( 'change', onChange );

		return () => Dimensions.removeEventListener( 'change', onChange );
	} );

	return dimensions;
};
github ampproject / amp-wp / assets / src / components / error-context-provider / index.js View on Github external
export function ErrorContextProvider( { children } ) {
	const [ error, setError ] = useState( error );

	return (
		
			{ children }
		
	);
}
github ampproject / amp-wp / assets / src / edit-story / components / dropzone / index.js View on Github external
function DropZone( { children, onDrop, pageIndex, dragIndicatorOffset } ) {
	const dropZoneElement = useRef( null );
	const [ dropZone, setDropZone ] = useState( null );
	const { actions: { registerDropZone, unregisterDropZone, resetHoverState }, state: { hoveredDropZone } } = useDropZone();

	useLayoutEffect( () => {
		setDropZone( {
			node: dropZoneElement.current,
		} );
	}, [ dropZoneElement ] );

	useLayoutEffect( () => {
		registerDropZone( dropZone );
		return () => {
			unregisterDropZone( dropZone );
			setDropZone( null );
		};
	}, [ dropZone, registerDropZone, unregisterDropZone ] );
github ampproject / amp-wp / assets / src / stories-editor / blocks / amp-story-page-attachment / attachment-content.js View on Github external
const AttachmentContent = ( props ) => {
	const [ selectedPost, setSelectedPost ] = useState( null );
	const [ failedToFetch, setFailedToFetch ] = useState( false );
	const [ searchValue, setSearchValue ] = useState( '' );
	const [ isFetching, setIsFetching ] = useState( false );
	const fetchRequest = useRef( null );
	const isStillMounted = useRef( true );

	const {
		attributes,
		setAttributes,
		toggleAttachment,
	} = props;

	const {
		attachmentClass,
		postId,
		postType,
		title,
		wrapperStyle,