Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Documentation] Add @example for getNotices to create example in the handbook. #42023

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
6438856
Add npmDevDependencies as a template variable. Update messaging to sh…
ryanwelcher Mar 24, 2022
6f24eb8
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Mar 25, 2022
0b691cc
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Apr 4, 2022
c847911
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Apr 9, 2022
b0b836e
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Apr 22, 2022
cdb77bc
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher May 19, 2022
8a59dff
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher May 24, 2022
505db7d
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 1, 2022
85af639
Merge branch 'trunk' of github.com:ryanwelcher/gutenberg into trunk
ryanwelcher Jun 1, 2022
c69e955
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 8, 2022
567a22c
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 9, 2022
c3de411
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 14, 2022
9d61058
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 22, 2022
ffc4a63
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 23, 2022
ce4613d
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 28, 2022
dcc53a0
Adds @example to the getNotices selector.
ryanwelcher Jun 28, 2022
614bb81
Merge remote-tracking branch 'upstream/trunk' into trunk
ryanwelcher Jun 29, 2022
7d39306
Merge branch 'trunk' of github.com:ryanwelcher/gutenberg into trunk
ryanwelcher Jun 29, 2022
5b079b5
Remove extra code block added in error.
ryanwelcher Jun 29, 2022
9f43623
Merge branch 'trunk' into feature/add-examples-to-notices-docs
ryanwelcher Jun 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/reference-guides/data/data-core-notices.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@ Namespace: `core/notices`.
Returns all notices as an array, optionally for a given context. Defaults to
the global context.

_Usage_

```js
// This example retrieves all notices and displays their messages in a unordered list.

const ExampleComponent = () => {
const notices = useSelect( ( select ) =>
select( 'core/notices' ).getNotices()
);
return (
<ul>
{ notices.map( ( notice ) => (
<li key={ notice.ID }>{ notice.content }</li>
) ) }
</ul>
);
};
```

_Parameters_

- _state_ `Object`: Notices state.
Expand Down
17 changes: 17 additions & 0 deletions packages/notices/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@ const DEFAULT_NOTICES = [];
* @param {Object} state Notices state.
* @param {?string} context Optional grouping context.
*
* @example
*
*```js
* // This example retrieves all notices and displays their messages in a unordered list.
*
* const ExampleComponent = () => {
* const notices = useSelect( ( select ) => select( 'core/notices' ).getNotices() );
* return (
* <ul>
* { notices.map( ( notice ) => (
* <li key={ notice.ID }>{ notice.content }</li>
* ) ) }
* </ul>
* )
* };
*```
*
* @return {WPNotice[]} Array of notices.
*/
export function getNotices( state, context = DEFAULT_CONTEXT ) {
Expand Down