-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 examples for all actions/selectors for the @wordpress/notice package. #42077
[Documentation] Add examples for all actions/selectors for the @wordpress/notice package. #42077
Conversation
…ow what packages are being installed.
…sNotice and createWarningNotice.
Tracking ticket for this effort is here - #42125 |
<Button | ||
onClick={ () => createNotice( 'success', __( 'Notice message' ) ) } | ||
> | ||
{ __( 'Generate a success notice!' ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to include all the required imports in this example, so useDispatch
and __
. Also, the preferred way of calling useDispatch
is by passing the imported store
object as follows:
import { store as noticesStore } from '@wordpress/notices';
// ...
const { createNotice } = useDispatch( noticesStore );
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I mean that for all the examples)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I love importing the store name suggestion. All examples are updated.
All the examples present how to use actions/selectors from the React component. In practice, it doesn't necessarily need to be the case. It's possible to use also the following snippet: import { select } from '@wordpress/data';
import { store as noticesStore } from '@wordpress/notices';
console.log( select( noticesStore ).getNotices() ); I'm not sure whether it's something we should include in the examples, but we definitely should make it clear that the usage depends on the context. |
It's certainly possible to use the selectors this way, and we can also access and use them by calling I think the majority of cases will be either in a block's Edit component or in a SlotFill which will also be a component. So I think it make sense to show examples for the most common usage. Is there a common use-case I am not considering? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work add all those examples.
I agree with that. That seems like the most common use case. On the flip side, it gives a false impression that you need React to use data stores. It's something we might want to emphasize in the documentation for |
What?
This PR introduces practical examples for the notice package documentation. Part of the effort in WordPress/Documentation-Issue-Tracker#379
Why?
WIthout examples, the data store APIs can be very confusing.