-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Extract Navigation Block data fetching and management to hook(s) #31825
Conversation
: false, | ||
}; | ||
}, | ||
[ menuId ] |
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.
Question: will this selector be retriggered when the selected menu ID (passed from placeholder.js
) changes?
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 think so. This should be similar to useEffect
dependencies.
Size Change: +91 B (0%) Total Size: 1.32 MB
ℹ️ View Unchanged
|
packages/block-library/src/navigation/use-navigation-entities.js
Outdated
Show resolved
Hide resolved
packages/block-library/src/navigation/use-navigation-entities.js
Outdated
Show resolved
Hide resolved
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.
LGTM
I couldn't spot any regressions for Navigation Block in Post/Site Editor, and Navigation Screen works as expected.
Description
Currently the logic for fetching and management of data (eg: Pages, Menus, Menu Items) in the Nav Block is placed inside the
placeholder.js
component. As we look to extract reusable logic (possibly into a@wordpress/menus
package) it's important that important logic such as this is not "buried" within specific components.Moreover, due to being placed inline within a component the data logic is currently all combined and difficult to read / comprehend.
To this end this PR breaks the data fetching out into separate (potentially reusable) hooks for each entity whilst providing a master utility hook
useNavigationEntities
which will pull through all entity data in one go.The benefits of this are:
@wordpress/menus
if required in future (aligns more closely with the Nav Editor data fetching implementation)How has this been tested?
Check all existing functionality is "as is". Nothing should change.
Particularly check that
Screenshots
Types of changes
New feature (non-breaking change which adds functionality)
Checklist:
*.native.js
files for terms that need renaming or removal).