使用法

  1. import { withNotices, Button } from '@wordpress/components';
  2. const MyComponentWithNotices = withNotices(
  3. ( { noticeOperations, noticeUI } ) => {
  4. const addError = () =>
  5. noticeOperations.createErrorNotice( 'Error message' );
  6. return (
  7. <div>
  8. { noticeUI }
  9. <Button variant="secondary" onClick={ addError }>
  10. Add error
  11. </Button>
  12. </div>
  13. );
  14. }
  15. );