withNotices is a React higher-order component used typically in adding the ability to post notice messages within the original component.

Wrapping the original component with withNotices encapsulates the component with the additional props noticeOperations, noticeUI, and noticeList.

Contains a number of useful functions to add notices to your site.

# createNotice
Function passed down as a prop that adds a new notice.


  • notice object: Notice to add.

# createErrorNotice
Function passed as a prop that adds a new error notice.


  • msg string: Error message of the notice.

# removeAllNotices
Function that removes all notices.

# removeNotice
Function that removes notice by ID.


  • id string: ID of notice to remove.

The rendered NoticeList.

The array of notice objects to be displayed.


import { withNotices, Button } from '@wordpress/components';

const MyComponentWithNotices = withNotices(
    ( { noticeOperations, noticeUI } ) => {
        const addError = () =>
            noticeOperations.createErrorNotice( 'Error message' );
        return (
                { noticeUI }
                <Button variant="secondary" onClick={ addError }>
                    Add error