when I update the attribute, the number of posts rendered in the block
don’t change
Yes, and that’s because you did not include the numberPosts
attribute in the second parameter (which is an array of dependencies) for useSelect()
, so the (memoized) value remains unchanged, even when the block’s state is changed, or that you selected a new number of posts via the range control.
So your useSelect()
should include the above dependency, i.e. use [ attributes.numberPosts ]
instead of []
as the 2nd parameter, like so:
const posts = useSelect( ( select ) => {
return select( 'core' ).getEntityRecords(
'postType',
'post',
{
'per_page': attributes.numberPosts
}
);
}, [ attributes.numberPosts ] ); // here, make sure you include all dependencies
Additionally, you should set a key
for your list items, e.g. <li key={ `post-${ post.id }` }>
.
Related Posts:
- Remove block styles in the Block Editor
- Are there ways to make the Gutenberg editor wider? And the HTML-block higher?
- Blocks: set a default value for a TextControl
- Is there a list / reference for all current native WordPress blocks?
- Setting default font family with theme.json
- (Gutenberg Block Editor) Using editor.BlockEdit filter, need to alter html/ CSS class of BlockEdit Component
- Extending Gutenberg group block: How to properly combine multiple attributes?
- Required (mandatory) Gutenberg block
- Add classname to Gutenberg block wrapper in the editor?
- How to develop custom blocks without triggering validation errors
- get selected categories or tags (using javascript) in GutenBerg?
- Help with using getBlockIndex
- Gutenberg blocks – processing server data within a block
- Best practices for CPT without using an editor [closed]
- Custom Gutenberg block is not showing up in inserter dialog
- Gutenberg – Custom blocks onClick not working?
- Get blocks from other pages, from within current page
- Your site doesn’t include support for the block… after registering a block
- .editor-styles-wrapper overriding my block styles in Gutenberg
- Remove a component fill from a Block Editor panel
- How to wrap the Gutenberg editor in a custom React component?
- Proper way to reload or update getEntityRecords state
- Cannot embed YouTube video
- Add a button to the toolbar of an existing Gutenberg block
- Gutenberg. How To Register A Custom Block Style For Specific Post Type Only
- get used blocks in post and detect changing
- JSON File in Gutenberg
- Show date post published in Gutenberg component
- Adding an html wrapper to a custom Block Pattern
- How to add a class to the element in a custom Gutenberg block
- Gutenberg: How to check if a block is used in a paginated post?
- Editor API Endpoint or Data Store That Provides a List of Meta Fields for Post Types
- Specify exact parent child relationship between two blocks
- Using custom Entities to retrieve external data in the Block Editor
- How can I remove a button from the paragraph block toolbar?
- Align Group blocks left or right
- Unable to override MediaPlaceholder component
- Run the edit function of parent block when something changes in InnerBlocks
- do_blocks does not include its CSS
- Track Block Pattern Insertion Within the Block Editor
- block variations registration in PHP
- How to add screen reader text to links inserted in the block editor?
- Auto synchronize saving of custom block editor entities
- Store data from nested block of gutenberg
- Output content of post excerpt into Innerblocks within Gutenberg block
- How to add a link in a translation in gutenberg
- component does not render in block save
- Adding block programmatically to InnerBlocks
- Filter root element of tag cloud block
- How `window.wp.oldEditor` is being set in the editor?
- How to use Gutenberg blocks in widgets?
- How do I access onMerge, onReplace, onRemove functions for a Rich Text component in Gutenberg block code?
- How can Reusable Blocks be fully deleted?
- Make a Gutenberg Block that do WP_User_Query
- Don’t expand “Most Used” accordion item when adding new block
- Is it possible (safe) to create custom blocks using ES Next format?
- How do i get the link to a block?
- Start a line with – without converting to list
- How to prevent Block Editor from adding id to block markup in save function?
- Dequeue Gutenburg Block Library CSS (‘wp-block-library’) in Admin
- How do I make sure the gutenberg block CSS is not disrupted by generic styles?
- Custom block Block Validation failure w/ deprecation declared
- Working with external library in gutenberg block
- Download Image from URL and Create a new Folder in wp-contents and save them there
- Using full site editing, can I edit just one specific post / page to be unique?
- Detect selected block pattern from a specific Pattern category
- Leave focus on custom Gutenberg block when pressing enter
- How to Analyze Blocks and find Intersection and patterns between pages
- WordPress does not hide content after “Read more” block added using gutenberg editor
- Gutenberg InnerBlocks allowed types and reusable blocks
- Issue with translation – Gutenberg
- How can I block embeds and show an individual preview image per block?
- RSS feed WP widget vs Gutenberg Block?
- Gutenberg editor failing to load correctly after new theme install
- Gutenberg Custom Style problem with background image
- Theme options missing from edit page
- How to activate a new prop that a block introduces in a new release?
- “Updating failed” if any text includes “$v()”
- Disable Font Size for Authors using: add_theme_support(‘disable-custom-font-sizes’);
- Multiple checkboxes Gutenberg control
- Block validation failed
- Loading column block style seperately
- wp-scripts start build hangs
- How to register multiple blocks
- How to edit post meta by post ID in Gutenberg
- How do I change bullet on categories block?
- Add a class to img of core/cover block
- Hide title block on edit screen in Gutenberg
- How can I disable fontSizes of the Paragraph block inside the Quote block with theme.json?
- Categories, tags and thumbnails panels are not visible in the Block editor’s post menu
- How to translate multiple blocks within one plugin
- How to disable the Code Editor in Gutenberg?
- Enable Gutenberg Editor when editing tags
- How to position more than one item over an image in a Gutenberg WordPress block theme
- Some CSS classes missing when rendering the page with get_the_content()
- Error with RichText Component
- Rem font size is different in the frontend and block editor
- Add to Media Inserter Categories
- Get attributes from last block created
- How do I make the block editor use https by default?