Replies: 1 comment
-
Discovered this about the first code example (copy-pasted here). import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
// ... (inside react render function)
const mediaId = 604;
useSelect(
select => {
const media = select(coreStore).getMedia(mediaId, { context: 'view' }); // undefined
return media;
},
[mediaId]
); This code works, but the output of const media = useSelect(
select => {
const media = select(coreStore).getMedia(mediaId, { context: 'view' }); // undefined
return media;
},
[mediaId]
)
if (!media) return "Loading...";
return <div>...</div> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In a custom block i'm trying to get an image from the media library, but i cannot get some data back, i only receive undefined.
But likely i'm doing some sort of mistake...
I've tried doing these but no one is working
or
Any suggestion?
I'm also wondering how to know every "getter" available in a store? And signature of invokation for each of them ? I cannot find a clear explanation in the docs.
For example I consider "getMedia" a getter.
Typescript says that "getMedia"do not exist in the type def of store coming from
@wordpress/core-data
, but at runtime in the browser I checked and the methods named "getMedia" exists in the store object.How to be self aware of all these getters, and how to use them?
Beta Was this translation helpful? Give feedback.
All reactions