|
515 | 515 | * @category Store hooks |
516 | 516 | */ |
517 | 517 | /// useTable |
| 518 | +/** |
| 519 | + * The useTableCellIds hook returns the Ids of every Cell used across the whole |
| 520 | + * Table, and registers a listener so that any changes to that result will cause |
| 521 | + * a re-render. |
| 522 | + * |
| 523 | + * A Provider component is used to wrap part of an application in a context, and |
| 524 | + * it can contain a default Store or a set of Store objects named by Id. The |
| 525 | + * useTableCellIds hook lets you indicate which Store to get data for: omit the |
| 526 | + * optional final parameter for the default context Store, provide an Id for a |
| 527 | + * named context Store, or provide a Store explicitly by reference. |
| 528 | + * |
| 529 | + * When first rendered, this hook will create a listener so that changes to the |
| 530 | + * Table Cell Ids will cause a re-render. When the component containing this |
| 531 | + * hook is unmounted, the listener will be automatically removed. |
| 532 | + * |
| 533 | + * @param tableId The Id of the Table in the Store. |
| 534 | + * @param storeOrStoreId The Store to be accessed: omit for the default context |
| 535 | + * Store, provide an Id for a named context Store, or provide an explicit |
| 536 | + * reference. |
| 537 | + * @returns An array of the Ids of every Cell used across the whole Table. |
| 538 | + * @example |
| 539 | + * This example creates a Store outside the application, which is used in the |
| 540 | + * useTableCellIds hook by reference. A change to the data in the Store |
| 541 | + * re-renders the component. |
| 542 | + * |
| 543 | + * ```jsx |
| 544 | + * const store = createStore().setCell('pets', 'fido', 'color', 'brown'); |
| 545 | + * const App = () => ( |
| 546 | + * <span>{JSON.stringify(useTableCellIds('pets', store))}</span> |
| 547 | + * ); |
| 548 | + * |
| 549 | + * const app = document.createElement('div'); |
| 550 | + * ReactDOMClient.createRoot(app).render(<App />); // !act |
| 551 | + * console.log(app.innerHTML); |
| 552 | + * // -> '<span>["color"]</span>' |
| 553 | + * |
| 554 | + * store.setCell('pets', 'felix', 'species', 'cat'); // !act |
| 555 | + * console.log(app.innerHTML); |
| 556 | + * // -> '<span>["color","species"]</span>' |
| 557 | + * ``` |
| 558 | + * @example |
| 559 | + * This example creates a Provider context into which a default Store is |
| 560 | + * provided. A component within it then uses the useTableCellIds hook. |
| 561 | + * |
| 562 | + * ```jsx |
| 563 | + * const App = ({store}) => ( |
| 564 | + * <Provider store={store}> |
| 565 | + * <Pane /> |
| 566 | + * </Provider> |
| 567 | + * ); |
| 568 | + * const Pane = () => <span>{JSON.stringify(useTableCellIds('pets'))}</span>; |
| 569 | + * |
| 570 | + * const store = createStore().setCell('pets', 'fido', 'color', 'brown'); |
| 571 | + * const app = document.createElement('div'); |
| 572 | + * ReactDOMClient.createRoot(app).render(<App store={store} />); // !act |
| 573 | + * console.log(app.innerHTML); |
| 574 | + * // -> '<span>["color"]</span>' |
| 575 | + * ``` |
| 576 | + * @example |
| 577 | + * This example creates a Provider context into which a Store is provided, named |
| 578 | + * by Id. A component within it then uses the useTableCellIds hook. |
| 579 | + * |
| 580 | + * ```jsx |
| 581 | + * const App = ({store}) => ( |
| 582 | + * <Provider storesById={{petStore: store}}> |
| 583 | + * <Pane /> |
| 584 | + * </Provider> |
| 585 | + * ); |
| 586 | + * const Pane = () => ( |
| 587 | + * <span>{JSON.stringify(useTableCellIds('pets', 'petStore'))}</span> |
| 588 | + * ); |
| 589 | + * |
| 590 | + * const store = createStore().setCell('pets', 'fido', 'color', 'brown'); |
| 591 | + * const app = document.createElement('div'); |
| 592 | + * ReactDOMClient.createRoot(app).render(<App store={store} />); // !act |
| 593 | + * console.log(app.innerHTML); |
| 594 | + * // -> '<span>["color"]</span>' |
| 595 | + * ``` |
| 596 | + * @category Store hooks |
| 597 | + * @since v3.3 |
| 598 | + */ |
| 599 | +/// useTableCellIds |
518 | 600 | /** |
519 | 601 | * The useRowIds hook returns the Ids of every Row in a given Table, and |
520 | 602 | * registers a listener so that any changes to that result will cause a |
|
594 | 676 | * @category Store hooks |
595 | 677 | */ |
596 | 678 | /// useRowIds |
| 679 | + |
597 | 680 | /** |
598 | 681 | * The useSortedRowIds hook returns the sorted (and optionally, paginated) Ids |
599 | 682 | * of every Row in a given Table, and registers a listener so that any changes |
|
0 commit comments