@wordpress/core-data 4.5.0 → 4.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/README.md +175 -85
  3. package/build/entities.js +49 -46
  4. package/build/entities.js.map +1 -1
  5. package/build/entity-types/{navigation-area.js → entities.js} +1 -1
  6. package/build/entity-types/{navigation-area.js.map → entities.js.map} +0 -0
  7. package/build/hooks/constants.js +0 -2
  8. package/build/hooks/constants.js.map +1 -1
  9. package/build/hooks/index.js +38 -0
  10. package/build/hooks/index.js.map +1 -0
  11. package/build/hooks/use-entity-record.js +22 -8
  12. package/build/hooks/use-entity-record.js.map +1 -1
  13. package/build/hooks/use-entity-records.js +21 -8
  14. package/build/hooks/use-entity-records.js.map +1 -1
  15. package/build/index.js +17 -21
  16. package/build/index.js.map +1 -1
  17. package/build/queried-data/get-query-parts.js +4 -0
  18. package/build/queried-data/get-query-parts.js.map +1 -1
  19. package/build/selectors.js +163 -163
  20. package/build/selectors.js.map +1 -1
  21. package/build-module/entities.js +49 -46
  22. package/build-module/entities.js.map +1 -1
  23. package/build-module/entity-types/entities.js +2 -0
  24. package/build-module/entity-types/{navigation-area.js.map → entities.js.map} +0 -0
  25. package/build-module/hooks/constants.js +0 -1
  26. package/build-module/hooks/constants.js.map +1 -1
  27. package/build-module/hooks/index.js +3 -0
  28. package/build-module/hooks/index.js.map +1 -0
  29. package/build-module/hooks/use-entity-record.js +18 -7
  30. package/build-module/hooks/use-entity-record.js.map +1 -1
  31. package/build-module/hooks/use-entity-records.js +17 -7
  32. package/build-module/hooks/use-entity-records.js.map +1 -1
  33. package/build-module/index.js +2 -3
  34. package/build-module/index.js.map +1 -1
  35. package/build-module/queried-data/get-query-parts.js +4 -0
  36. package/build-module/queried-data/get-query-parts.js.map +1 -1
  37. package/build-module/selectors.js +164 -163
  38. package/build-module/selectors.js.map +1 -1
  39. package/package.json +12 -12
  40. package/src/entities.ts +342 -129
  41. package/src/entity-types/entities.ts +127 -0
  42. package/src/entity-types/index.ts +1 -3
  43. package/src/hooks/constants.ts +1 -2
  44. package/src/hooks/index.ts +8 -0
  45. package/src/hooks/test/use-entity-record.js +1 -0
  46. package/src/hooks/test/use-entity-records.js +1 -0
  47. package/src/hooks/test/use-query-select.js +1 -0
  48. package/src/hooks/use-entity-record.ts +32 -9
  49. package/src/hooks/use-entity-records.ts +28 -30
  50. package/src/index.js +2 -3
  51. package/src/queried-data/get-query-parts.js +3 -0
  52. package/src/queried-data/test/get-query-parts.js +4 -0
  53. package/src/selectors.ts +406 -216
  54. package/src/test/actions.js +30 -14
  55. package/src/test/entities.js +5 -0
  56. package/src/test/resolvers.js +11 -0
  57. package/build-module/entity-types/navigation-area.js +0 -2
  58. package/src/entity-types/navigation-area.ts +0 -29
package/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.8.0 (2022-06-01)
6
+
7
+ ## 4.7.0 (2022-05-18)
8
+
9
+ ### New Features
10
+
11
+ - Stabilized the `useEntityRecord` and `useEntityRecords` hooks ([#40162](https://github.com/WordPress/gutenberg/pull/40162))
12
+
13
+ ## 4.6.0 (2022-05-04)
14
+
5
15
  ## 4.5.0 (2022-04-21)
6
16
 
7
17
  ## 4.4.0 (2022-04-08)
@@ -9,7 +19,7 @@
9
19
  ## 4.3.0 (2022-03-23)
10
20
 
11
21
  ### New Features
12
- The saveEntityRecord, saveEditedEntityRecord, and deleteEntityRecord actions now accept an optional throwOnError option (defaults to false). When set to true, any exceptions occurring when the action was executing are re-thrown, causing dispatch().saveEntityRecord() to reject with an error. ([#39258](https://github.com/WordPress/gutenberg/pull/39258))
22
+ - The saveEntityRecord, saveEditedEntityRecord, and deleteEntityRecord actions now accept an optional throwOnError option (defaults to false). When set to true, any exceptions occurring when the action was executing are re-thrown, causing dispatch().saveEntityRecord() to reject with an error. ([#39258](https://github.com/WordPress/gutenberg/pull/39258))
13
23
  - Added support for fetching block patterns and their categories, with the `getBlockPatterns` and `getBlockPatternCategories` selectors.
14
24
 
15
25
  ## 4.2.0 (2022-03-11)
package/README.md CHANGED
@@ -265,14 +265,14 @@ Calling this may trigger an OPTIONS request to the REST API via the
265
265
 
266
266
  _Parameters_
267
267
 
268
- - _state_ `Object`: Data state.
268
+ - _state_ `State`: Data state.
269
269
  - _action_ `string`: Action to check. One of: 'create', 'read', 'update', 'delete'.
270
270
  - _resource_ `string`: REST resource to check, e.g. 'media' or 'posts'.
271
- - _id_ `string=`: Optional ID of the rest resource to check.
271
+ - _id_ `RecordKey`: Optional ID of the rest resource to check.
272
272
 
273
273
  _Returns_
274
274
 
275
- - `boolean|undefined`: Whether or not the user can perform the action, or `undefined` if the OPTIONS request is still being made.
275
+ - `boolean | undefined`: Whether or not the user can perform the action, or `undefined` if the OPTIONS request is still being made.
276
276
 
277
277
  ### canUserEditEntityRecord
278
278
 
@@ -285,14 +285,14 @@ Calling this may trigger an OPTIONS request to the REST API via the
285
285
 
286
286
  _Parameters_
287
287
 
288
- - _state_ `Object`: Data state.
288
+ - _state_ `State`: Data state.
289
289
  - _kind_ `string`: Entity kind.
290
290
  - _name_ `string`: Entity name.
291
- - _recordId_ `string`: Record's id.
291
+ - _recordId_ `RecordKey`: Record's id.
292
292
 
293
293
  _Returns_
294
294
 
295
- - `boolean|undefined`: Whether or not the user can edit, or `undefined` if the OPTIONS request is still being made.
295
+ - `boolean | undefined`: Whether or not the user can edit, or `undefined` if the OPTIONS request is still being made.
296
296
 
297
297
  ### getAuthors
298
298
 
@@ -302,12 +302,12 @@ Returns all available authors.
302
302
 
303
303
  _Parameters_
304
304
 
305
- - _state_ `Object`: Data state.
306
- - _query_ `Object|undefined`: Optional object of query parameters to include with request.
305
+ - _state_ `State`: Data state.
306
+ - _query_ `EntityQuery< any >`: Optional object of query parameters to include with request.
307
307
 
308
308
  _Returns_
309
309
 
310
- - `Array`: Authors list.
310
+ - `User< 'edit' >[]`: Authors list.
311
311
 
312
312
  ### getAutosave
313
313
 
@@ -315,14 +315,14 @@ Returns the autosave for the post and author.
315
315
 
316
316
  _Parameters_
317
317
 
318
- - _state_ `Object`: State tree.
318
+ - _state_ `State`: State tree.
319
319
  - _postType_ `string`: The type of the parent post.
320
- - _postId_ `number`: The id of the parent post.
321
- - _authorId_ `number`: The id of the author.
320
+ - _postId_ `RecordKey`: The id of the parent post.
321
+ - _authorId_ `RecordKey`: The id of the author.
322
322
 
323
323
  _Returns_
324
324
 
325
- - `?Object`: The autosave for the post and author.
325
+ - `EntityRecord | undefined`: The autosave for the post and author.
326
326
 
327
327
  ### getAutosaves
328
328
 
@@ -333,13 +333,13 @@ author for each post.
333
333
 
334
334
  _Parameters_
335
335
 
336
- - _state_ `Object`: State tree.
336
+ - _state_ `State`: State tree.
337
337
  - _postType_ `string`: The type of the parent post.
338
- - _postId_ `number`: The id of the parent post.
338
+ - _postId_ `RecordKey`: The id of the parent post.
339
339
 
340
340
  _Returns_
341
341
 
342
- - `?Array`: An array of autosaves for the post, or undefined if there is none.
342
+ - `Array< any > | undefined`: An array of autosaves for the post, or undefined if there is none.
343
343
 
344
344
  ### getBlockPatternCategories
345
345
 
@@ -347,11 +347,11 @@ Retrieve the list of registered block pattern categories.
347
347
 
348
348
  _Parameters_
349
349
 
350
- - _state_ `Object`: Data state.
350
+ - _state_ `State`: Data state.
351
351
 
352
352
  _Returns_
353
353
 
354
- - `Array`: Block pattern category list.
354
+ - `Array< any >`: Block pattern category list.
355
355
 
356
356
  ### getBlockPatterns
357
357
 
@@ -359,11 +359,11 @@ Retrieve the list of registered block patterns.
359
359
 
360
360
  _Parameters_
361
361
 
362
- - _state_ `Object`: Data state.
362
+ - _state_ `State`: Data state.
363
363
 
364
364
  _Returns_
365
365
 
366
- - `Array`: Block pattern list.
366
+ - `Array< any >`: Block pattern list.
367
367
 
368
368
  ### getCurrentTheme
369
369
 
@@ -371,11 +371,11 @@ Return the current theme.
371
371
 
372
372
  _Parameters_
373
373
 
374
- - _state_ `Object`: Data state.
374
+ - _state_ `State`: Data state.
375
375
 
376
376
  _Returns_
377
377
 
378
- - `Object`: The current theme.
378
+ - `any`: The current theme.
379
379
 
380
380
  ### getCurrentUser
381
381
 
@@ -383,11 +383,11 @@ Returns the current user.
383
383
 
384
384
  _Parameters_
385
385
 
386
- - _state_ `Object`: Data state.
386
+ - _state_ `State`: Data state.
387
387
 
388
388
  _Returns_
389
389
 
390
- - `Object`: Current user object.
390
+ - `User< 'edit' >`: Current user object.
391
391
 
392
392
  ### getEditedEntityRecord
393
393
 
@@ -395,14 +395,14 @@ Returns the specified entity record, merged with its edits.
395
395
 
396
396
  _Parameters_
397
397
 
398
- - _state_ `Object`: State tree.
398
+ - _state_ `State`: State tree.
399
399
  - _kind_ `string`: Entity kind.
400
400
  - _name_ `string`: Entity name.
401
- - _recordId_ `number|string`: Record ID.
401
+ - _recordId_ `RecordKey`: Record ID.
402
402
 
403
403
  _Returns_
404
404
 
405
- - `Object?`: The entity record, merged with its edits.
405
+ - `EntityRecord | undefined`: The entity record, merged with its edits.
406
406
 
407
407
  ### getEmbedPreview
408
408
 
@@ -410,12 +410,12 @@ Returns the embed preview for the given URL.
410
410
 
411
411
  _Parameters_
412
412
 
413
- - _state_ `Object`: Data state.
413
+ - _state_ `State`: Data state.
414
414
  - _url_ `string`: Embedded URL.
415
415
 
416
416
  _Returns_
417
417
 
418
- - `*`: Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
418
+ - `any`: Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
419
419
 
420
420
  ### getEntitiesByKind
421
421
 
@@ -425,12 +425,12 @@ Returns the loaded entities for the given kind.
425
425
 
426
426
  _Parameters_
427
427
 
428
- - _state_ `Object`: Data state.
428
+ - _state_ `State`: Data state.
429
429
  - _kind_ `string`: Entity kind.
430
430
 
431
431
  _Returns_
432
432
 
433
- - `Array<Object>`: Array of entities with config matching kind.
433
+ - `Array< any >`: Array of entities with config matching kind.
434
434
 
435
435
  ### getEntitiesConfig
436
436
 
@@ -438,12 +438,12 @@ Returns the loaded entities for the given kind.
438
438
 
439
439
  _Parameters_
440
440
 
441
- - _state_ `Object`: Data state.
441
+ - _state_ `State`: Data state.
442
442
  - _kind_ `string`: Entity kind.
443
443
 
444
444
  _Returns_
445
445
 
446
- - `Array<Object>`: Array of entities with config matching kind.
446
+ - `Array< any >`: Array of entities with config matching kind.
447
447
 
448
448
  ### getEntity
449
449
 
@@ -453,13 +453,13 @@ Returns the entity config given its kind and name.
453
453
 
454
454
  _Parameters_
455
455
 
456
- - _state_ `Object`: Data state.
456
+ - _state_ `State`: Data state.
457
457
  - _kind_ `string`: Entity kind.
458
458
  - _name_ `string`: Entity name.
459
459
 
460
460
  _Returns_
461
461
 
462
- - `Object`: Entity config
462
+ - `any`: Entity config
463
463
 
464
464
  ### getEntityConfig
465
465
 
@@ -467,13 +467,13 @@ Returns the entity config given its kind and name.
467
467
 
468
468
  _Parameters_
469
469
 
470
- - _state_ `Object`: Data state.
470
+ - _state_ `State`: Data state.
471
471
  - _kind_ `string`: Entity kind.
472
472
  - _name_ `string`: Entity name.
473
473
 
474
474
  _Returns_
475
475
 
476
- - `Object`: Entity config
476
+ - `any`: Entity config
477
477
 
478
478
  ### getEntityRecord
479
479
 
@@ -483,15 +483,15 @@ entity object if it exists and is received.
483
483
 
484
484
  _Parameters_
485
485
 
486
- - _state_ `Object`: State tree
486
+ - _state_ `State`: State tree
487
487
  - _kind_ `string`: Entity kind.
488
488
  - _name_ `string`: Entity name.
489
- - _key_ `number`: Record's key
490
- - _query_ `?Object`: Optional query.
489
+ - _key_ `RecordKey`: Record's key
490
+ - _query_ `EntityQuery< any >`: Optional query.
491
491
 
492
492
  _Returns_
493
493
 
494
- - `Object|undefined`: Record.
494
+ - `EntityRecord | undefined`: Record.
495
495
 
496
496
  ### getEntityRecordEdits
497
497
 
@@ -499,14 +499,14 @@ Returns the specified entity record's edits.
499
499
 
500
500
  _Parameters_
501
501
 
502
- - _state_ `Object`: State tree.
502
+ - _state_ `State`: State tree.
503
503
  - _kind_ `string`: Entity kind.
504
504
  - _name_ `string`: Entity name.
505
- - _recordId_ `number`: Record ID.
505
+ - _recordId_ `RecordKey`: Record ID.
506
506
 
507
507
  _Returns_
508
508
 
509
- - `Object?`: The entity record's edits.
509
+ - `Optional< any >`: The entity record's edits.
510
510
 
511
511
  ### getEntityRecordNonTransientEdits
512
512
 
@@ -518,14 +518,14 @@ They are defined in the entity's config.
518
518
 
519
519
  _Parameters_
520
520
 
521
- - _state_ `Object`: State tree.
521
+ - _state_ `State`: State tree.
522
522
  - _kind_ `string`: Entity kind.
523
523
  - _name_ `string`: Entity name.
524
- - _recordId_ `number`: Record ID.
524
+ - _recordId_ `RecordKey`: Record ID.
525
525
 
526
526
  _Returns_
527
527
 
528
- - `Object?`: The entity record's non transient edits.
528
+ - `Optional< any >`: The entity record's non transient edits.
529
529
 
530
530
  ### getEntityRecords
531
531
 
@@ -533,14 +533,14 @@ Returns the Entity's records.
533
533
 
534
534
  _Parameters_
535
535
 
536
- - _state_ `Object`: State tree
536
+ - _state_ `State`: State tree
537
537
  - _kind_ `string`: Entity kind.
538
538
  - _name_ `string`: Entity name.
539
- - _query_ `?Object`: Optional terms query.
539
+ - _query_ `EntityQuery< any >`: Optional terms query.
540
540
 
541
541
  _Returns_
542
542
 
543
- - `?Array`: Records.
543
+ - `Array< EntityRecord > | undefined`: Records.
544
544
 
545
545
  ### getLastEntityDeleteError
546
546
 
@@ -548,14 +548,14 @@ Returns the specified entity record's last delete error.
548
548
 
549
549
  _Parameters_
550
550
 
551
- - _state_ `Object`: State tree.
551
+ - _state_ `State`: State tree.
552
552
  - _kind_ `string`: Entity kind.
553
553
  - _name_ `string`: Entity name.
554
- - _recordId_ `number`: Record ID.
554
+ - _recordId_ `RecordKey`: Record ID.
555
555
 
556
556
  _Returns_
557
557
 
558
- - `Object?`: The entity record's save error.
558
+ - `any`: The entity record's save error.
559
559
 
560
560
  ### getLastEntitySaveError
561
561
 
@@ -563,14 +563,14 @@ Returns the specified entity record's last save error.
563
563
 
564
564
  _Parameters_
565
565
 
566
- - _state_ `Object`: State tree.
566
+ - _state_ `State`: State tree.
567
567
  - _kind_ `string`: Entity kind.
568
568
  - _name_ `string`: Entity name.
569
- - _recordId_ `number`: Record ID.
569
+ - _recordId_ `RecordKey`: Record ID.
570
570
 
571
571
  _Returns_
572
572
 
573
- - `Object?`: The entity record's save error.
573
+ - `any`: The entity record's save error.
574
574
 
575
575
  ### getRawEntityRecord
576
576
 
@@ -579,14 +579,14 @@ with its attributes mapped to their raw values.
579
579
 
580
580
  _Parameters_
581
581
 
582
- - _state_ `Object`: State tree.
582
+ - _state_ `State`: State tree.
583
583
  - _kind_ `string`: Entity kind.
584
584
  - _name_ `string`: Entity name.
585
- - _key_ `number`: Record's key.
585
+ - _key_ `RecordKey`: Record's key.
586
586
 
587
587
  _Returns_
588
588
 
589
- - `Object?`: Object with the entity's raw attributes.
589
+ - `EntityRecord | undefined`: Object with the entity's raw attributes.
590
590
 
591
591
  ### getRedoEdit
592
592
 
@@ -595,11 +595,11 @@ for the entity records edits history, if any.
595
595
 
596
596
  _Parameters_
597
597
 
598
- - _state_ `Object`: State tree.
598
+ - _state_ `State`: State tree.
599
599
 
600
600
  _Returns_
601
601
 
602
- - `Object?`: The edit.
602
+ - `Optional< any >`: The edit.
603
603
 
604
604
  ### getReferenceByDistinctEdits
605
605
 
@@ -616,11 +616,11 @@ _Usage_
616
616
 
617
617
  _Parameters_
618
618
 
619
- - _state_ `Object`: Editor state.
619
+ - _state_ `State`: Editor state.
620
620
 
621
621
  _Returns_
622
622
 
623
- - `*`: A value whose reference will change only when an edit occurs.
623
+ - A value whose reference will change only when an edit occurs.
624
624
 
625
625
  ### getThemeSupports
626
626
 
@@ -628,11 +628,11 @@ Return theme supports data in the index.
628
628
 
629
629
  _Parameters_
630
630
 
631
- - _state_ `Object`: Data state.
631
+ - _state_ `State`: Data state.
632
632
 
633
633
  _Returns_
634
634
 
635
- - `*`: Index data.
635
+ - `any`: Index data.
636
636
 
637
637
  ### getUndoEdit
638
638
 
@@ -641,11 +641,11 @@ for the entity records edits history, if any.
641
641
 
642
642
  _Parameters_
643
643
 
644
- - _state_ `Object`: State tree.
644
+ - _state_ `State`: State tree.
645
645
 
646
646
  _Returns_
647
647
 
648
- - `Object?`: The edit.
648
+ - `Optional< any >`: The edit.
649
649
 
650
650
  ### getUserQueryResults
651
651
 
@@ -653,12 +653,12 @@ Returns all the users returned by a query ID.
653
653
 
654
654
  _Parameters_
655
655
 
656
- - _state_ `Object`: Data state.
656
+ - _state_ `State`: Data state.
657
657
  - _queryID_ `string`: Query ID.
658
658
 
659
659
  _Returns_
660
660
 
661
- - `Array`: Users list.
661
+ - `User< 'edit' >[]`: Users list.
662
662
 
663
663
  ### hasEditsForEntityRecord
664
664
 
@@ -667,10 +667,10 @@ and false otherwise.
667
667
 
668
668
  _Parameters_
669
669
 
670
- - _state_ `Object`: State tree.
670
+ - _state_ `State`: State tree.
671
671
  - _kind_ `string`: Entity kind.
672
672
  - _name_ `string`: Entity name.
673
- - _recordId_ `number|string`: Record ID.
673
+ - _recordId_ `RecordKey`: Record ID.
674
674
 
675
675
  _Returns_
676
676
 
@@ -683,10 +683,10 @@ or false otherwise.
683
683
 
684
684
  _Parameters_
685
685
 
686
- - _state_ `Object`: State tree
686
+ - _state_ `State`: State tree
687
687
  - _kind_ `string`: Entity kind.
688
688
  - _name_ `string`: Entity name.
689
- - _query_ `?Object`: Optional terms query.
689
+ - _query_ `EntityQuery< any >`: Optional terms query.
690
690
 
691
691
  _Returns_
692
692
 
@@ -698,9 +698,9 @@ Returns true if the REST request for autosaves has completed.
698
698
 
699
699
  _Parameters_
700
700
 
701
- - _state_ `Object`: State tree.
701
+ - _state_ `State`: State tree.
702
702
  - _postType_ `string`: The type of the parent post.
703
- - _postId_ `number`: The id of the parent post.
703
+ - _postId_ `RecordKey`: The id of the parent post.
704
704
 
705
705
  _Returns_
706
706
 
@@ -713,7 +713,7 @@ for the entity records edits history, and false otherwise.
713
713
 
714
714
  _Parameters_
715
715
 
716
- - _state_ `Object`: State tree.
716
+ - _state_ `State`: State tree.
717
717
 
718
718
  _Returns_
719
719
 
@@ -726,7 +726,7 @@ for the entity records edits history, and false otherwise.
726
726
 
727
727
  _Parameters_
728
728
 
729
- - _state_ `Object`: State tree.
729
+ - _state_ `State`: State tree.
730
730
 
731
731
  _Returns_
732
732
 
@@ -738,10 +738,10 @@ Returns true if the specified entity record is autosaving, and false otherwise.
738
738
 
739
739
  _Parameters_
740
740
 
741
- - _state_ `Object`: State tree.
741
+ - _state_ `State`: State tree.
742
742
  - _kind_ `string`: Entity kind.
743
743
  - _name_ `string`: Entity name.
744
- - _recordId_ `number`: Record ID.
744
+ - _recordId_ `RecordKey`: Record ID.
745
745
 
746
746
  _Returns_
747
747
 
@@ -753,10 +753,10 @@ Returns true if the specified entity record is deleting, and false otherwise.
753
753
 
754
754
  _Parameters_
755
755
 
756
- - _state_ `Object`: State tree.
756
+ - _state_ `State`: State tree.
757
757
  - _kind_ `string`: Entity kind.
758
758
  - _name_ `string`: Entity name.
759
- - _recordId_ `number`: Record ID.
759
+ - _recordId_ `RecordKey`: Record ID.
760
760
 
761
761
  _Returns_
762
762
 
@@ -772,7 +772,7 @@ get back from the oEmbed preview API.
772
772
 
773
773
  _Parameters_
774
774
 
775
- - _state_ `Object`: Data state.
775
+ - _state_ `State`: Data state.
776
776
  - _url_ `string`: Embedded URL.
777
777
 
778
778
  _Returns_
@@ -786,7 +786,7 @@ otherwise.
786
786
 
787
787
  _Parameters_
788
788
 
789
- - _state_ `Object`: Data state.
789
+ - _state_ `State`: Data state.
790
790
  - _url_ `string`: URL the preview would be for.
791
791
 
792
792
  _Returns_
@@ -799,10 +799,10 @@ Returns true if the specified entity record is saving, and false otherwise.
799
799
 
800
800
  _Parameters_
801
801
 
802
- - _state_ `Object`: State tree.
802
+ - _state_ `State`: State tree.
803
803
  - _kind_ `string`: Entity kind.
804
804
  - _name_ `string`: Entity name.
805
- - _recordId_ `number|string`: Record ID.
805
+ - _recordId_ `RecordKey`: Record ID.
806
806
 
807
807
  _Returns_
808
808
 
@@ -810,6 +810,96 @@ _Returns_
810
810
 
811
811
  <!-- END TOKEN(Autogenerated selectors|src/selectors.ts) -->
812
812
 
813
+ ## Hooks
814
+
815
+ The following set of react hooks available to import from the `@wordpress/core-data` package:
816
+
817
+ <!-- START TOKEN(Autogenerated hooks|src/hooks/index.ts) -->
818
+
819
+ ### useEntityRecord
820
+
821
+ Resolves the specified entity record.
822
+
823
+ _Usage_
824
+
825
+ ```js
826
+ import { useEntityRecord } from '@wordpress/core-data';
827
+
828
+ function PageTitleDisplay( { id } ) {
829
+ const { record, isResolving } = useEntityRecord( 'postType', 'page', id );
830
+
831
+ if ( isResolving ) {
832
+ return 'Loading...';
833
+ }
834
+
835
+ return record.title;
836
+ }
837
+
838
+ // Rendered in the application:
839
+ // <PageTitleDisplay id={ 1 } />
840
+ ```
841
+
842
+ In the above example, when `PageTitleDisplay` is rendered into an
843
+ application, the page and the resolution details will be retrieved from
844
+ the store state using `getEntityRecord()`, or resolved if missing.
845
+
846
+ _Parameters_
847
+
848
+ - _kind_ `string`: Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
849
+ - _name_ `string`: Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
850
+ - _recordId_ `string | number`: ID of the requested entity record.
851
+ - _options_ `Options`: Optional hook options.
852
+
853
+ _Returns_
854
+
855
+ - `EntityRecordResolution< RecordType >`: Entity record data.
856
+
857
+ ### useEntityRecords
858
+
859
+ Resolves the specified entity records.
860
+
861
+ _Usage_
862
+
863
+ ```js
864
+ import { useEntityRecord } from '@wordpress/core-data';
865
+
866
+ function PageTitlesList() {
867
+ const { records, isResolving } = useEntityRecords( 'postType', 'page' );
868
+
869
+ if ( isResolving ) {
870
+ return 'Loading...';
871
+ }
872
+
873
+ return (
874
+ <ul>
875
+ { records.map( ( page ) => (
876
+ <li>{ page.title }</li>
877
+ ) ) }
878
+ </ul>
879
+ );
880
+ }
881
+
882
+ // Rendered in the application:
883
+ // <PageTitlesList />
884
+ ```
885
+
886
+ In the above example, when `PageTitlesList` is rendered into an
887
+ application, the list of records and the resolution details will be retrieved from
888
+ the store state using `getEntityRecords()`, or resolved if missing.
889
+
890
+ _Parameters_
891
+
892
+ - _kind_ `string`: Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.
893
+ - _name_ `string`: Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.
894
+ - _queryArgs_ `Record< string, unknown >`: Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.
895
+ - _options_ `Options`: Optional hook options.
896
+
897
+ _Returns_
898
+
899
+ - `EntityRecordsResolution< RecordType >`: Entity records data.
900
+
901
+ <!-- END TOKEN(Autogenerated hooks|src/hooks/index.ts) -->
902
+
813
903
  ## Contributing to this package
814
904
 
815
905
  This is an individual package that's part of the Gutenberg project. The project is organized as a monorepo. It's made up of multiple self-contained software packages, each with a specific purpose. The packages in this monorepo are published to [npm](https://www.npmjs.com/) and used by [WordPress](https://make.wordpress.org/core/) as well as other software projects.