-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Editor: Refactor the 'PostVisibility' component #69451
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import { useSelect } from '@wordpress/data'; | |
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { visibilityOptions } from './utils'; | ||
| import { VISIBILITY_OPTIONS } from './utils'; | ||
| import { store as editorStore } from '../../store'; | ||
|
|
||
| /** | ||
|
|
@@ -24,8 +24,11 @@ export default function PostVisibilityLabel() { | |
| * @return {string} Post visibility label. | ||
| */ | ||
| export function usePostVisibilityLabel() { | ||
| const visibility = useSelect( ( select ) => | ||
| select( editorStore ).getEditedPostVisibility() | ||
| const visibility = useSelect( | ||
| ( select ) => select( editorStore ).getEditedPostVisibility(), | ||
| [] | ||
| ); | ||
| return visibilityOptions[ visibility ]?.label; | ||
|
|
||
| return VISIBILITY_OPTIONS.find( ( option ) => option.value === visibility ) | ||
| ?.label; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a question: is
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to change |
||
| } | ||
This file was deleted.
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.
Just a question: why adding the dependencies empty array?
Uh oh!
There was an error while loading. Please reload this page.
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.
This is just a best practice.
useSelectis similar touseEffect, dependencies need to be provided and empty array means same thing. In this case, only re-select values when component mounts or store updates.