You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+62-3Lines changed: 62 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ function MyComponent( props ) {
46
46
| `uniqueContentItems` | `bool` | `true` | Prevent duplicate items from being picked.
47
47
| `excludeCurrentPost` | `bool` | `true` | Don't allow user to pick the current post. Only applicable on the editor screen.
48
48
| `content` | `array` | `[]` | Array of items to prepopulate picker with. Must be in the format of: `[{id: 1, type: 'post'}, {id: 1, type: 'page'},... ]`. You cannot provide terms and posts to the same picker. Can also take the form `[1, 2, ...]` if only one `contentTypes` is provided.
49
-
49
+
| `perPage` | `number` | `50` | Number of items to show during search
50
50
__NOTE:__ Content picker cannot validate that posts you pass it via `content` prop actually exist. If a post does not exist, it will not render as one of the picked items but will still be passed back as picked items if new items are picked/sorted. Therefore, on save you need to validate that all the picked posts/terms actually exist.
51
51
52
52
The `contentTypes` will get used in a Rest Request to the `search` endpoint as the `subtypes`:
@@ -87,7 +87,7 @@ function MyComponent( props ) {
87
87
|`placeholder`|`string`|`''`| Renders placeholder text inside the Search Field. |
88
88
|`contentTypes`|`array`|`[ 'post', 'page' ]`| Names of the post types or taxonomies that should get searched |
89
89
|`excludeItems`|`array`|`[ { id: 1, type: 'post' ]`| Items to exclude from search |
90
-
90
+
| `perPage` | `number` | `50` | Number of items to show during search
91
91
92
92
93
93
## useHasSelectedInnerBlock
@@ -108,10 +108,69 @@ function BlockEdit( props ) {
108
108
)
109
109
}
110
110
```
111
+
## useRequestData
112
+
Custom hook to to make a request using `getEntityRecords` or `getEntityRecord` that provides `data`, `isLoading` and `invalidator` function. The hook determines which selector to use based on the query parameter. If a number is passed, it will use `getEntityRecord` to retrieve a single item. If an object is passed, it will use that as the query for `getEntityRecords` to retrieve multiple pieces of data.
113
+
114
+
The `invalidator` function, when dispatched, will tell the datastore to invalidate the resolver associated with the request made by getEntityRecords. This will trigger the request to be re-run as if it was being requested for the first time. This is not always needed but is very useful for components that need to update the data after an event. For example, displaying a list of uploaded media after a new item has been uploaded.
115
+
116
+
Parameters:
117
+
*`{string}` entity The entity to retrieve. ie. postType
118
+
*`{string}` kind The entity kind to retrieve. ie. posts
119
+
*`{Object|Number}` Optional. Query to pass to the geEntityRecords request. Defaults to an empty object. If a number is passed, it is used as the ID of the entity to retrieve via getEntityRecord.
120
+
121
+
Returns:
122
+
*`{Array}`
123
+
*`{Array} ` Array containing the requested entity kind.
124
+
*`{Boolean}` Representing if the request is resolving
125
+
*`{Function}` This function will invalidate the resolver and re-run the query.
A wrapper component that only renders child components if the current user has admin capabilities. The usecase for this component is when you have a certain setting that should be restricted to administrators only. For example when you have a block that requires an API token or crenentials you might only want Administrators to edit these. See [10up/maps-block-apple](https://github.com/10up/maps-block-apple/blob/774c6509eabb7ac48dcebea551f32ac7ddc5d246/src/Settings/AuthenticationSettings.js) for a real world example.
173
+
A wrapper component that only renders child components if the current user has admin capabilities. The use case for this component is when you have a certain setting that should be restricted to administrators only. For example when you have a block that requires an API token or credentials you might only want Administrators to edit these. See [10up/maps-block-apple](https://github.com/10up/maps-block-apple/blob/774c6509eabb7ac48dcebea551f32ac7ddc5d246/src/Settings/AuthenticationSettings.js) for a real world example.
* Hook for retrieving data from the WordPress REST API.
14
+
*
15
+
* @param {string} entity The entity to retrieve. ie. postType
16
+
* @param {string} kind The entity kind to retrieve. ie. posts
17
+
* @param {Object | number} [query] Optional. Query to pass to the geEntityRecords request. Defaults to an empty object. If a number is passed, it is used as the ID of the entity to retrieve via getEntityRecord.
18
+
* @return {Array} The data returned from the request.
0 commit comments