{"id":134613,"date":"2021-03-09T08:38:24","date_gmt":"2021-03-09T08:38:24","guid":{"rendered":"https:\/\/developer.wordpress.org\/block-editor\/reference-guides\/data\/data-core-notices\/"},"modified":"2026-06-07T06:31:38","modified_gmt":"2026-06-07T06:31:38","slug":"data-core-notices","status":"publish","type":"blocks-handbook","link":"https:\/\/developer.wordpress.org\/block-editor\/reference-guides\/data\/data-core-notices\/","title":{"rendered":"Notices Data"},"content":{"rendered":"<p>Namespace: <code>core\/notices<\/code>.<\/p>\n<h2>Selectors<\/h2>\n<p><!-- START TOKEN(Autogenerated selectors|..\/..\/..\/packages\/notices\/src\/store\/selectors.ts) --><\/p>\n<h3>getNotices<\/h3>\n<p>Returns all notices as an array, optionally for a given context. Defaults to the global context.<\/p>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { useSelect } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\n\nconst ExampleComponent = () =&gt; {\n    const notices = useSelect( ( select ) =&gt;\n        select( noticesStore ).getNotices()\n    );\n    return (\n        &lt;ul&gt;\n            { notices.map( ( notice ) =&gt; (\n                &lt;li key={ notice.ID }&gt;{ notice.content }&lt;\/li&gt;\n            ) ) }\n        &lt;\/ul&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>state<\/em> <code>Record&lt; string, Array&lt; Notice &gt; &gt;<\/code>: Notices state.<\/li>\n<li><em>context<\/em> <code>string<\/code>: Optional grouping context.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li>Array of notices.<\/li>\n<\/ul>\n<p><!-- END TOKEN(Autogenerated selectors|..\/..\/..\/packages\/notices\/src\/store\/selectors.ts) --><\/p>\n<h2>Actions<\/h2>\n<p><!-- START TOKEN(Autogenerated actions|..\/..\/..\/packages\/notices\/src\/store\/actions.ts) --><\/p>\n<h3>createErrorNotice<\/h3>\n<p>Returns an action object used in signalling that an error notice is to be created. Refer to <code>createNotice<\/code> for options documentation.<\/p>\n<p><em>Related<\/em><\/p>\n<ul>\n<li>createNotice<\/li>\n<\/ul>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { __ } from '@wordpress\/i18n';\nimport { useDispatch } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\nimport { Button } from '@wordpress\/components';\n\nconst ExampleComponent = () =&gt; {\n    const { createErrorNotice } = useDispatch( noticesStore );\n    return (\n        &lt;Button\n            onClick={ () =&gt;\n                createErrorNotice( __( 'An error occurred!' ), {\n                    type: 'snackbar',\n                    explicitDismiss: true,\n                } )\n            }\n        &gt;\n            { __(\n                'Generate a snackbar error notice with explicit dismiss button.'\n            ) }\n        &lt;\/Button&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>content<\/em> <code>string<\/code>: Notice message.<\/li>\n<li><em>options<\/em> <code>NoticeOptions<\/code>: Optional notice options.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li>Action object.<\/li>\n<\/ul>\n<h3>createInfoNotice<\/h3>\n<p>Returns an action object used in signalling that an info notice is to be created. Refer to <code>createNotice<\/code> for options documentation.<\/p>\n<p><em>Related<\/em><\/p>\n<ul>\n<li>createNotice<\/li>\n<\/ul>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { __ } from '@wordpress\/i18n';\nimport { useDispatch } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\nimport { Button } from '@wordpress\/components';\n\nconst ExampleComponent = () =&gt; {\n    const { createInfoNotice } = useDispatch( noticesStore );\n    return (\n        &lt;Button\n            onClick={ () =&gt;\n                createInfoNotice( __( 'Something happened!' ), {\n                    isDismissible: false,\n                } )\n            }\n        &gt;\n            { __( 'Generate a notice that cannot be dismissed.' ) }\n        &lt;\/Button&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>content<\/em> <code>string<\/code>: Notice message.<\/li>\n<li><em>options<\/em> <code>NoticeOptions<\/code>: Optional notice options.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li>Action object.<\/li>\n<\/ul>\n<h3>createNotice<\/h3>\n<p>Returns an action object used in signalling that a notice is to be created.<\/p>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { __ } from '@wordpress\/i18n';\nimport { useDispatch } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\nimport { Button } from '@wordpress\/components';\n\nconst ExampleComponent = () =&gt; {\n    const { createNotice } = useDispatch( noticesStore );\n    return (\n        &lt;Button\n            onClick={ () =&gt; createNotice( 'success', __( 'Notice message' ) ) }\n        &gt;\n            { __( 'Generate a success notice!' ) }\n        &lt;\/Button&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>status<\/em> Notice status (&#8220;info&#8221; if undefined is passed).<\/li>\n<li><em>content<\/em> <code>string<\/code>: Notice message.<\/li>\n<li><em>options<\/em> <code>NoticeOptions<\/code>: Optional notice options.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li><code>Extract&lt; ReducerAction, { type: 'CREATE_NOTICE'; } &gt;<\/code>: Action object.<\/li>\n<\/ul>\n<h3>createSuccessNotice<\/h3>\n<p>Returns an action object used in signalling that a success notice is to be created. Refer to <code>createNotice<\/code> for options documentation.<\/p>\n<p><em>Related<\/em><\/p>\n<ul>\n<li>createNotice<\/li>\n<\/ul>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { __ } from '@wordpress\/i18n';\nimport { useDispatch } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\nimport { Button } from '@wordpress\/components';\n\nconst ExampleComponent = () =&gt; {\n    const { createSuccessNotice } = useDispatch( noticesStore );\n    return (\n        &lt;Button\n            onClick={ () =&gt;\n                createSuccessNotice( __( 'Success!' ), {\n                    type: 'snackbar',\n                    icon: '\ud83d\udd25',\n                } )\n            }\n        &gt;\n            { __( 'Generate a snackbar success notice!' ) }\n        &lt;\/Button&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>content<\/em> <code>string<\/code>: Notice message.<\/li>\n<li><em>options<\/em> <code>NoticeOptions<\/code>: Optional notice options.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li>Action object.<\/li>\n<\/ul>\n<h3>createWarningNotice<\/h3>\n<p>Returns an action object used in signalling that a warning notice is to be created. Refer to <code>createNotice<\/code> for options documentation.<\/p>\n<p><em>Related<\/em><\/p>\n<ul>\n<li>createNotice<\/li>\n<\/ul>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { __ } from '@wordpress\/i18n';\nimport { useDispatch } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\nimport { Button } from '@wordpress\/components';\n\nconst ExampleComponent = () =&gt; {\n    const { createWarningNotice, createInfoNotice } =\n        useDispatch( noticesStore );\n    return (\n        &lt;Button\n            onClick={ () =&gt;\n                createWarningNotice( __( 'Warning!' ), {\n                    onDismiss: () =&gt; {\n                        createInfoNotice(\n                            __( 'The warning has been dismissed!' )\n                        );\n                    },\n                } )\n            }\n        &gt;\n            { __( 'Generates a warning notice with onDismiss callback' ) }\n        &lt;\/Button&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>content<\/em> <code>string<\/code>: Notice message.<\/li>\n<li><em>options<\/em> <code>NoticeOptions<\/code>: Optional notice options.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li>Action object.<\/li>\n<\/ul>\n<h3>removeAllNotices<\/h3>\n<p>Removes all notices from a given context. Defaults to the default context.<\/p>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { __ } from '@wordpress\/i18n';\nimport { useDispatch, useSelect } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\nimport { Button } from '@wordpress\/components';\n\nexport const ExampleComponent = () =&gt; {\n    const notices = useSelect( ( select ) =&gt;\n        select( noticesStore ).getNotices()\n    );\n    const { removeAllNotices } = useDispatch( noticesStore );\n    return (\n        &lt;&gt;\n            &lt;ul&gt;\n                { notices.map( ( notice ) =&gt; (\n                    &lt;li key={ notice.id }&gt;{ notice.content }&lt;\/li&gt;\n                ) ) }\n            &lt;\/ul&gt;\n            &lt;Button onClick={ () =&gt; removeAllNotices() }&gt;\n                { __( 'Clear all notices', 'woo-gutenberg-products-block' ) }\n            &lt;\/Button&gt;\n            &lt;Button onClick={ () =&gt; removeAllNotices( 'snackbar' ) }&gt;\n                { __(\n                    'Clear all snackbar notices',\n                    'woo-gutenberg-products-block'\n                ) }\n            &lt;\/Button&gt;\n        &lt;\/&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>noticeType<\/em> The context to remove all notices from.<\/li>\n<li><em>context<\/em> <code>string<\/code>: The optional context to remove all notices from.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li><code>Extract&lt; ReducerAction, { type: 'REMOVE_ALL_NOTICES'; } &gt;<\/code>: Action object.<\/li>\n<\/ul>\n<h3>removeNotice<\/h3>\n<p>Returns an action object used in signalling that a notice is to be removed.<\/p>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { __ } from '@wordpress\/i18n';\nimport { useDispatch } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\nimport { Button } from '@wordpress\/components';\n\nconst ExampleComponent = () =&gt; {\n    const notices = useSelect( ( select ) =&gt;\n        select( noticesStore ).getNotices()\n    );\n    const { createWarningNotice, removeNotice } = useDispatch( noticesStore );\n\n    return (\n        &lt;&gt;\n            &lt;Button\n                onClick={ () =&gt;\n                    createWarningNotice( __( 'Warning!' ), {\n                        isDismissible: false,\n                    } )\n                }\n            &gt;\n                { __( 'Generate a notice' ) }\n            &lt;\/Button&gt;\n            { notices.length &gt; 0 &amp;&amp; (\n                &lt;Button onClick={ () =&gt; removeNotice( notices[ 0 ].id ) }&gt;\n                    { __( 'Remove the notice' ) }\n                &lt;\/Button&gt;\n            ) }\n        &lt;\/&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>id<\/em> <code>string<\/code>: Notice unique identifier.<\/li>\n<li><em>context<\/em> <code>string<\/code>: Optional context (grouping) in which the notice is intended to appear. Defaults to &#8216;default&#8217; context.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li><code>Extract&lt; ReducerAction, { type: 'REMOVE_NOTICE'; } &gt;<\/code>: Action object.<\/li>\n<\/ul>\n<h3>removeNotices<\/h3>\n<p>Returns an action object used in signalling that several notices are to be removed.<\/p>\n<p><em>Usage<\/em><\/p>\n<pre><code class=\"language-js\">import { __ } from '@wordpress\/i18n';\nimport { useDispatch, useSelect } from '@wordpress\/data';\nimport { store as noticesStore } from '@wordpress\/notices';\nimport { Button } from '@wordpress\/components';\n\nconst ExampleComponent = () =&gt; {\n    const notices = useSelect( ( select ) =&gt;\n        select( noticesStore ).getNotices()\n    );\n    const { removeNotices } = useDispatch( noticesStore );\n    return (\n        &lt;&gt;\n            &lt;ul&gt;\n                { notices.map( ( notice ) =&gt; (\n                    &lt;li key={ notice.id }&gt;{ notice.content }&lt;\/li&gt;\n                ) ) }\n            &lt;\/ul&gt;\n            &lt;Button\n                onClick={ () =&gt;\n                    removeNotices( notices.map( ( { id } ) =&gt; id ) )\n                }\n            &gt;\n                { __( 'Clear all notices' ) }\n            &lt;\/Button&gt;\n        &lt;\/&gt;\n    );\n};\n<\/code><\/pre>\n<p><em>Parameters<\/em><\/p>\n<ul>\n<li><em>ids<\/em> <code>Array&lt; string &gt;<\/code>: List of unique notice identifiers.<\/li>\n<li><em>context<\/em> <code>string<\/code>: Optional context (grouping) in which the notices are intended to appear. Defaults to &#8216;default&#8217; context.<\/li>\n<\/ul>\n<p><em>Returns<\/em><\/p>\n<ul>\n<li><code>Extract&lt; ReducerAction, { type: 'REMOVE_NOTICES'; } &gt;<\/code>: Action object.<\/li>\n<\/ul>\n<p><!-- END TOKEN(Autogenerated actions|..\/..\/..\/packages\/notices\/src\/store\/actions.ts) --><\/p>\n","protected":false},"author":0,"featured_media":0,"parent":134606,"menu_order":500,"template":"","meta":{"footnotes":""},"class_list":["post-134613","blocks-handbook","type-blocks-handbook","status-publish","hentry","type-handbook"],"revision_note":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/developer.wordpress.org\/wp-json\/wp\/v2\/blocks-handbook\/134613","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/developer.wordpress.org\/wp-json\/wp\/v2\/blocks-handbook"}],"about":[{"href":"https:\/\/developer.wordpress.org\/wp-json\/wp\/v2\/types\/blocks-handbook"}],"version-history":[{"count":15,"href":"https:\/\/developer.wordpress.org\/wp-json\/wp\/v2\/blocks-handbook\/134613\/revisions"}],"predecessor-version":[{"id":160680,"href":"https:\/\/developer.wordpress.org\/wp-json\/wp\/v2\/blocks-handbook\/134613\/revisions\/160680"}],"up":[{"embeddable":true,"href":"https:\/\/developer.wordpress.org\/wp-json\/wp\/v2\/blocks-handbook\/134606"}],"wp:attachment":[{"href":"https:\/\/developer.wordpress.org\/wp-json\/wp\/v2\/media?parent=134613"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}