WithNotices Edit

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 and noticeUI.

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.


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

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