block-components
block-components copied to clipboard
Add useRenderAppenderWithLimit hook
Description of the Change
This pull request introduces a new custom React hook, useRenderAppenderWithLimit, which allows developers to easily enforce a maximum number of inner blocks in WordPress blocks. It also demonstrates its usage by adding an example block and updates the block components package to export the new hook.
New Hook Implementation and Documentation
- Added
useRenderAppenderWithLimithook inhooks/use-render-appender-with-limit/index.ts, which conditionally returns a block appender based on the number of inner blocks and a specified limit. - Provided documentation for the hook in
hooks/use-render-appender-with-limit/readme.md, including usage instructions and an example.
Example Block Demonstrating the Hook
- Created a new block,
example/inner-block-limit, with configuration inexample/src/blocks/inner-blocks-limit/block.jsonto showcase usage of the hook. - Implemented the block edit component in
example/src/blocks/inner-blocks-limit/edit.tsx, utilizing the hook to limit inner blocks to four. - Registered the block in
example/src/blocks/inner-blocks-limit/index.tsx, wiring up the edit and save functionality.
Package Export Update
- Exported
useRenderAppenderWithLimitfrom the main hooks index for easier import throughout the codebase.
Closes https://github.com/10up/block-components/issues/393
How to test the Change
Changelog Entry
Added - New Hook
Credits
Props @ncoetzer @fabiankaegy
Checklist:
- [ ] I agree to follow this project's Code of Conduct.
- [ ] I have updated the documentation accordingly.
- [ ] I have added Critical Flows, Test Cases, and/or End-to-End Tests to cover my change.
- [ ] All new and existing tests pass.
10up Block Components
Run #1057
Run Properties:
Passed #1057 •
6f752fca48: Enhance documentation for useRenderAppenderWithLimit hook by adding detailed par...
| Project |
10up Block Components
|
| Branch Review |
feature/hook-render-appender-with-limit
|
| Run status |
|
| Run duration | 05m 07s |
| Commit |
|
| Committer | Neil Coetzer |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
35
|
| View all changes introduced in this branch ↗︎ | |