Skip to content

Commit

Permalink
Add code fence around action example
Browse files Browse the repository at this point in the history
  • Loading branch information
opr committed Sep 11, 2022
1 parent cc42bd7 commit effe1ce
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
42 changes: 19 additions & 23 deletions docs/reference-guides/data/data-core-notices.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,35 +272,31 @@ Removes all notices from a given context. Defaults to the default context.

_Usage_

import { \_\_ } from '@wordpress/i18n';
```js
import { __ } from '@wordpress/i18n';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';
import { Button } from '@wordpress/components';

export const ExampleComponent = () => {
const notices = useSelect( ( select ) =>
select( noticesStore ).getNotices()
);
const { removeNotices } = useDispatch( noticesStore );
return (
\<>

<ul>
{ notices.map( ( notice ) => (
<li key={ notice.id }>{ notice.content }</li>
) ) }
</ul>
<Button
onClick={ () =>
removeAllNotices()
}
>
{ __( 'Clear all notices', 'woo-gutenberg-products-block' ) }
</Button>
</>
);

const notices = useSelect( ( select ) =>
select( noticesStore ).getNotices()
);
const { removeNotices } = useDispatch( noticesStore );
return (
<>
<ul>
{ notices.map( ( notice ) => (
<li key={ notice.id }>{ notice.content }</li>
) ) }
</ul>
<Button onClick={ () => removeAllNotices() }>
{ __( 'Clear all notices', 'woo-gutenberg-products-block' ) }
</Button>
</>
);
};
```

_Parameters_

Expand Down
2 changes: 2 additions & 0 deletions packages/notices/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ export function removeNotice( id, context = DEFAULT_CONTEXT ) {
* @param {string} context The context to remove all notices from.
*
* @example
* ```js
* import { __ } from '@wordpress/i18n';
* import { useDispatch, useSelect } from '@wordpress/data';
* import { store as noticesStore } from '@wordpress/notices';
Expand Down Expand Up @@ -347,6 +348,7 @@ export function removeNotice( id, context = DEFAULT_CONTEXT ) {
* </>
* );
* };
* ```
*
* @return {Object} Action object.
*/
Expand Down

0 comments on commit effe1ce

Please sign in to comment.