Finally, I found out how to do it.
Just call fetchApi in componentDidMount and then create a new state in your component and add the response to this state when the request is done:
constructor(props) {
super(props);
this.state = {
data: {},
};
}
componentDidMount() {
apiFetch( { path: '/wp/v2/users/1' } )
.then(data => this.setState({ data }));
}
then in render:
const { data } = this.state;
finally in return for example avatar of author:
<div className={className}>
{ data.avatar_url ? (<img src={data.avatar_url['24']} />) : (<></>) }
</div>
Related Posts:
- Plugin Sidebar is not Saving Meta Attribute to Post/Page after “Update”
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- REST API error in block editor for custom templates
- check if Gutenberg is currently in use
- How to use PanelColorSettings in custom Gutenberg block?
- Custom action button in Gutenberg editor (post_submitbox_misc_actions – equivalent)
- How to check WordPress website username and password is correct
- Adding pre-publish checks with Gutenberg
- Managing two editable fields in gutenberg
- How to make repeated component/block in Gutenberg
- How to save block attributes when the output doesn’t change
- How to remove unwanted panels inside InspectorControls from core blocks in Gutenberg
- Using Primary Color in Plugin Block
- WordPress REST API call generates nonce twice on every call
- Gutenberg ServerSideRender is deprecated, how to work with new wp.serverSideRender component?
- How to get data from WordPress $wpdb into React Gutenberg Blocks Frontend?
- lodash dependency in a Gutenberg plugin
- How to: Rest endpoint returning empty object
- Create Element From Dynamic HTML String [closed]
- Custom endpoint that returns an xml
- Rest Api How to get results of child categories with one api call
- creating elements/innerblocks via rangecontrol
- What’s the Right Way to get and save remote data for a Gutenberg block?
- WordPress: After Gutenberg plugin migration to block.json the localization/ translations with PolyGlot in JavaScript does not work anymore
- Looking for callback function after Gutenberg is rendered?
- How to Parse an Array of Elements in Gutenberg Block
- WP rest api v2 posts filter by ‘search’ & ‘category_name’ not working
- Error : “Updating failed: The response is not a valid JSON response” with custom shortcode
- Using the component outside the editor. select(‘core’) is null
- Gutenberg is there a way to know if the current block is reusable?
- How to disable “Transform to” option in Gutenberg custom blocks
- How to allow core Gutenberg blocks selection only when you are inside a custom inner block
- Is there a better way to implement responsive images than what WordPress uses by default?
- Gutenberg registerFormatType with Multiple Classes
- What method to use to call a REST API?
- Saving data from block editor to the database
- Gutenberg: useDispatch is not a function – @wordpress/data included
- Gutenberg Block add element in the Editor inside InnerBlocks after div – editor-block-list
- Make a list with header and subtext in Gutenberg blocks
- Gutenberg – What is the best way to save/update post meta?
- How do you render_callback for register_block_type to a method in another class?
- How to create multiple Gutenberg blocks in one plugin
- How to get color name in PanelColorSettings in custom Gutenberg block?
- How insert negative values in Gutenberg box-control
- Initial help with official “create a block” tutorial
- WP REST API V2 – Add user data to response
- Are block templates incompatible with serialize_blocks?
- How do I dynamically render an InnerBlock inside a dynamic block?
- ServerSideRender and Media Object: attributes passing image data object to php renderer even though it’s not set
- Gutenberg Block showing invalid content on edit
- WordPress Block Development – trouble importing from @wordpress/icons
- Gutenberg blocks not getting styled on back end
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- How to get results of subcategories also?(WP Rest Api v2)
- Is there an additional block.json property to set to get an InnerBlocks child to respect the “supports” property?
- How to setAttributes in Gutenberg block?
- How to access noticeOperations from withNotices
- Run code once when block is created
- Best way to save custom css for an block
- How to prevent UNDO on guternberg block editor
- How to insert text at the current cursor position in Gutenberg?
- How to override gutenberg paragraph block edit property
- Amending REST API function without deactivate/activate plugin every time changes is made
- How can I listen to events in Gutenberg block?
- It’s possible to passing a ref to FormTokenField from parent component using forwardRef?
- Create a new post using rest api and save featured image using an external image url
- Do I have to worry about useState causing a re-render?
- What’s the right way to instantiate new blocks and/or the plugin itself in toto when using wppb architecture?
- Getting meta in editor plugin, and event triggering issue
- WP Gutenberg Blocks – How to limit first/root blocks
- Creating a custom Gutenberg block with columns
- How to get boolean value from register_meta properly?
- JSX in WordPress Plugin Development
- Adding custom end points, No error line
- ResizableBox with RangeControl not working
- How can I get the selected string when using a toolbar button in Gutenberg?
- jQuery selectors for editor elements safe to use?
- There is a problem in the gutenberg block I developed. Problem is with withInstanceId
- Gutenberg: import dependency or assign from global variable?
- Serve text/html from wp-json API via WPEngine, headers not being set properly
- Secure REST with nonce works only when not logged
- How to do POST request with WP REST API v2 to custom table?
- Gutenberg table block with Bootstrap .table class
- How to control an elements classes from multiple Gutenberg sidebar controls?
- How to add a gradient component to a custom block
- rest_no_route on custom API endpoint wordpress
- How to only load css for used blocks on frontend
- Custom Rest Endpoint: Post/Put/Patch not working
- Additional classes `undefined` after saving post in Gutenberg
- How do you submit a Gutenberg plugin?
- Catching Gutenberg sidebar switch event
- Can’t retrieve body params from PUT endpoint using formdata
- Invalid hook call on save, not edit when using swiper slider
- Proper way to use useSelect
- Use npm and wp-env to make production bundle
- How to add template colors to custom block options in WordPress Gutenberg editor sidebar?
- How to save post meta as an array in Gutenberg?
- Do I need to create an endpoint?
- WordPress Rest API with rest_do_request, possible race condition?
- Gutenberg blocks error: Each child in a list should have a unique “key” prop