@aweebit/react-essentials 0.9.0 → 0.10.1
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.
- package/README.md +410 -67
- package/dist/misc/contextualize.d.ts +71 -0
- package/dist/misc/contextualize.d.ts.map +1 -0
- package/dist/misc/contextualize.js +63 -0
- package/dist/misc/contextualize.js.map +1 -0
- package/dist/misc/createSafeContext.d.ts +4 -35
- package/dist/misc/createSafeContext.d.ts.map +1 -1
- package/dist/misc/createSafeContext.js +2 -5
- package/dist/misc/createSafeContext.js.map +1 -1
- package/dist/misc/index.d.ts +2 -0
- package/dist/misc/index.d.ts.map +1 -1
- package/dist/misc/index.js +2 -0
- package/dist/misc/index.js.map +1 -1
- package/dist/misc/wrapJSX.d.ts +76 -0
- package/dist/misc/wrapJSX.d.ts.map +1 -0
- package/dist/misc/wrapJSX.js +61 -0
- package/dist/misc/wrapJSX.js.map +1 -0
- package/package.json +3 -2
- package/scripts/fixReadmeLinks.js +23 -0
- package/src/misc/contextualize.tsx +90 -0
- package/src/misc/createSafeContext.ts +8 -39
- package/src/misc/index.ts +2 -0
- package/src/misc/wrapJSX.tsx +107 -0
package/README.md
CHANGED
|
@@ -2,22 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@aweebit/react-essentials)
|
|
4
4
|
|
|
5
|
-
### Requirements
|
|
6
|
-
|
|
7
|
-
- React ≥ 18
|
|
8
|
-
- TypeScript ≥ 5.4
|
|
9
|
-
|
|
10
|
-
### Functions
|
|
11
|
-
|
|
12
5
|
- [useEventListener()](#useeventlistener)
|
|
13
6
|
- [useReducerWithDeps()](#usereducerwithdeps)
|
|
14
7
|
- [useStateWithDeps()](#usestatewithdeps)
|
|
8
|
+
- [contextualize()](#contextualize)
|
|
15
9
|
- [createSafeContext()](#createsafecontext)
|
|
10
|
+
- [wrapJSX()](#wrapjsx)
|
|
16
11
|
|
|
17
|
-
###
|
|
12
|
+
### Requirements
|
|
18
13
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
14
|
+
- React ≥ 18
|
|
15
|
+
- TypeScript ≥ 5.4
|
|
21
16
|
|
|
22
17
|
## useEventListener
|
|
23
18
|
|
|
@@ -25,7 +20,7 @@
|
|
|
25
20
|
const useEventListener: UseEventListener;
|
|
26
21
|
```
|
|
27
22
|
|
|
28
|
-
Defined in: [hooks/useEventListener.ts:135](https://github.com/aweebit/react-essentials/blob/v0.
|
|
23
|
+
Defined in: [hooks/useEventListener.ts:135](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useEventListener.ts#L135)
|
|
29
24
|
|
|
30
25
|
Adds `handler` as a listener for the event `eventName` of `target` with the
|
|
31
26
|
provided `options` applied
|
|
@@ -37,7 +32,7 @@ function useEventListener(eventName, handler, options?): void;
|
|
|
37
32
|
function useEventListener(target, eventName, handler, options?): void;
|
|
38
33
|
```
|
|
39
34
|
|
|
40
|
-
For the full definition of the hook's type, see [`UseEventListener`](#useeventlistener).
|
|
35
|
+
For the full definition of the hook's type, see [`UseEventListener`](#useeventlistener-1).
|
|
41
36
|
|
|
42
37
|
If `target` is not provided, `window` is used instead.
|
|
43
38
|
|
|
@@ -62,7 +57,7 @@ useEventListener(buttonRef, 'click', () => console.log('click'));
|
|
|
62
57
|
|
|
63
58
|
### See
|
|
64
59
|
|
|
65
|
-
[`UseEventListener`](#useeventlistener)
|
|
60
|
+
[`UseEventListener`](#useeventlistener-1)
|
|
66
61
|
|
|
67
62
|
---
|
|
68
63
|
|
|
@@ -76,7 +71,7 @@ function useReducerWithDeps<S, A>(
|
|
|
76
71
|
): [S, ActionDispatch<A>];
|
|
77
72
|
```
|
|
78
73
|
|
|
79
|
-
Defined in: [hooks/useReducerWithDeps.ts:59](https://github.com/aweebit/react-essentials/blob/v0.
|
|
74
|
+
Defined in: [hooks/useReducerWithDeps.ts:59](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useReducerWithDeps.ts#L59)
|
|
80
75
|
|
|
81
76
|
`useReducer` hook with an additional dependency array `deps` that resets the
|
|
82
77
|
state to `initialState` when dependencies change
|
|
@@ -219,7 +214,7 @@ function useStateWithDeps<S>(
|
|
|
219
214
|
): [S, Dispatch<SetStateAction<S>>];
|
|
220
215
|
```
|
|
221
216
|
|
|
222
|
-
Defined in: [hooks/useStateWithDeps.ts:62](https://github.com/aweebit/react-essentials/blob/v0.
|
|
217
|
+
Defined in: [hooks/useStateWithDeps.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useStateWithDeps.ts#L62)
|
|
223
218
|
|
|
224
219
|
`useState` hook with an additional dependency array `deps` that resets the
|
|
225
220
|
state to `initialState` when dependencies change
|
|
@@ -343,15 +338,113 @@ Dependencies that reset the state to `initialState`
|
|
|
343
338
|
|
|
344
339
|
---
|
|
345
340
|
|
|
341
|
+
## contextualize()
|
|
342
|
+
|
|
343
|
+
```ts
|
|
344
|
+
function contextualize(jsx): ContextualizePipe;
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
Defined in: [misc/contextualize.tsx:79](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/misc/contextualize.tsx#L79)
|
|
348
|
+
|
|
349
|
+
An alternative way to provide context values to component trees that avoids
|
|
350
|
+
ever-increasing indentation
|
|
351
|
+
|
|
352
|
+
A context-specific version of the more general [`wrapJSX`](#wrapjsx) function.
|
|
353
|
+
|
|
354
|
+
### Example
|
|
355
|
+
|
|
356
|
+
```tsx
|
|
357
|
+
// Before:
|
|
358
|
+
return (
|
|
359
|
+
<CourseIdContext.Provider value={courseId}>
|
|
360
|
+
<DeckIdContext.Provider value={deckId}>
|
|
361
|
+
<FlashcardsContext.Provider value={flashcards}>
|
|
362
|
+
<EventHandlersContext.Provider value={eventHandlers}>
|
|
363
|
+
<Header />
|
|
364
|
+
<Main />
|
|
365
|
+
<Footer />
|
|
366
|
+
</EventHandlersContext.Provider>
|
|
367
|
+
</FlashcardsContext.Provider>
|
|
368
|
+
</DeckIdContext.Provider>
|
|
369
|
+
</CourseIdContext.Provider>
|
|
370
|
+
);
|
|
371
|
+
|
|
372
|
+
// After:
|
|
373
|
+
const jsx = (
|
|
374
|
+
<>
|
|
375
|
+
<Header />
|
|
376
|
+
<Main />
|
|
377
|
+
<Footer />
|
|
378
|
+
</>
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
return contextualize(jsx)
|
|
382
|
+
.with(EventHandlersContext, eventHandlers)
|
|
383
|
+
.with(FlashcardsContext, flashcards)
|
|
384
|
+
.with(DeckIdContext, deckId)
|
|
385
|
+
.with(CourseIdContext, courseId)
|
|
386
|
+
.end();
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Parameters
|
|
390
|
+
|
|
391
|
+
<table>
|
|
392
|
+
<thead>
|
|
393
|
+
<tr>
|
|
394
|
+
<th>Parameter</th>
|
|
395
|
+
<th>Type</th>
|
|
396
|
+
<th>Description</th>
|
|
397
|
+
</tr>
|
|
398
|
+
</thead>
|
|
399
|
+
<tbody>
|
|
400
|
+
<tr>
|
|
401
|
+
<td>
|
|
402
|
+
|
|
403
|
+
`jsx`
|
|
404
|
+
|
|
405
|
+
</td>
|
|
406
|
+
<td>
|
|
407
|
+
|
|
408
|
+
`Element`
|
|
409
|
+
|
|
410
|
+
</td>
|
|
411
|
+
<td>
|
|
412
|
+
|
|
413
|
+
The JSX to contextualize
|
|
414
|
+
|
|
415
|
+
</td>
|
|
416
|
+
</tr>
|
|
417
|
+
</tbody>
|
|
418
|
+
</table>
|
|
419
|
+
|
|
420
|
+
### Returns
|
|
421
|
+
|
|
422
|
+
[`ContextualizePipe`](#contextualizepipe)
|
|
423
|
+
|
|
424
|
+
An object with the following properties:
|
|
425
|
+
|
|
426
|
+
- `with`: a function that accepts a context `Context` and a value `value` for
|
|
427
|
+
it as arguments and returns
|
|
428
|
+
`contextualize(<Context.Provider value={value}>{jsx}</Context.Provider>)`
|
|
429
|
+
- `end`: a function that returns `jsx`
|
|
430
|
+
|
|
431
|
+
### See
|
|
432
|
+
|
|
433
|
+
[`ContextualizePipe`](#contextualizepipe)
|
|
434
|
+
|
|
435
|
+
---
|
|
436
|
+
|
|
346
437
|
## createSafeContext()
|
|
347
438
|
|
|
348
439
|
```ts
|
|
349
|
-
function createSafeContext<T>(): <DisplayName>(
|
|
350
|
-
|
|
351
|
-
|
|
440
|
+
function createSafeContext<T>(): <DisplayName>(displayName) => {
|
|
441
|
+
[K in `${string}Context`]: Context<T>;
|
|
442
|
+
} & {
|
|
443
|
+
[K in `use${string}`]: () => T;
|
|
444
|
+
};
|
|
352
445
|
```
|
|
353
446
|
|
|
354
|
-
Defined in: [misc/createSafeContext.ts:
|
|
447
|
+
Defined in: [misc/createSafeContext.ts:62](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/misc/createSafeContext.ts#L62)
|
|
355
448
|
|
|
356
449
|
For a given type `T`, returns a function that produces both a context of that
|
|
357
450
|
type and a hook that returns the current context value if one was provided,
|
|
@@ -371,7 +464,7 @@ enum Direction {
|
|
|
371
464
|
Right,
|
|
372
465
|
}
|
|
373
466
|
|
|
374
|
-
// Before
|
|
467
|
+
// Before:
|
|
375
468
|
const DirectionContext = createContext<Direction | undefined>(undefined);
|
|
376
469
|
DirectionContext.displayName = 'DirectionContext';
|
|
377
470
|
|
|
@@ -388,7 +481,7 @@ const useDirection = () => {
|
|
|
388
481
|
return direction;
|
|
389
482
|
};
|
|
390
483
|
|
|
391
|
-
// After
|
|
484
|
+
// After:
|
|
392
485
|
const { DirectionContext, useDirection } =
|
|
393
486
|
createSafeContext<Direction>()('Direction'); // That's it :)
|
|
394
487
|
|
|
@@ -437,7 +530,7 @@ A function that accepts a single string argument `displayName` (e.g.
|
|
|
437
530
|
current context value if one was provided, or throws an error otherwise
|
|
438
531
|
|
|
439
532
|
```ts
|
|
440
|
-
<DisplayName>(displayName):
|
|
533
|
+
<DisplayName>(displayName): { [K in `${string}Context`]: Context<T> } & { [K in `use${string}`]: () => T };
|
|
441
534
|
```
|
|
442
535
|
|
|
443
536
|
#### Type Parameters
|
|
@@ -486,11 +579,101 @@ A function that accepts a single string argument `displayName` (e.g.
|
|
|
486
579
|
|
|
487
580
|
#### Returns
|
|
488
581
|
|
|
489
|
-
[`
|
|
582
|
+
``{ [K in `${string}Context`]: Context<T> }`` & ``{ [K in `use${string}`]: () => T }``
|
|
583
|
+
|
|
584
|
+
---
|
|
585
|
+
|
|
586
|
+
## wrapJSX()
|
|
587
|
+
|
|
588
|
+
```ts
|
|
589
|
+
function wrapJSX(jsx): JSXWrapPipe;
|
|
590
|
+
```
|
|
591
|
+
|
|
592
|
+
Defined in: [misc/wrapJSX.tsx:93](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/misc/wrapJSX.tsx#L93)
|
|
593
|
+
|
|
594
|
+
An alternative way to compose JSX that avoids ever-increasing indentation
|
|
595
|
+
|
|
596
|
+
A more general version of the context-specific [`contextualize`](#contextualize)
|
|
597
|
+
function.
|
|
598
|
+
|
|
599
|
+
### Example
|
|
600
|
+
|
|
601
|
+
```tsx
|
|
602
|
+
// Before:
|
|
603
|
+
createRoot(document.getElementById('root')!).render(
|
|
604
|
+
<StrictMode>
|
|
605
|
+
<I18nextProvider i18n={i18n}>
|
|
606
|
+
<QueryClientProvider client={queryClient}>
|
|
607
|
+
<NuqsAdapter>
|
|
608
|
+
<ThemeProvider theme={theme}>
|
|
609
|
+
<ToasterProvider>
|
|
610
|
+
<App />
|
|
611
|
+
</ToasterProvider>
|
|
612
|
+
</ThemeProvider>
|
|
613
|
+
</NuqsAdapter>
|
|
614
|
+
</QueryClientProvider>
|
|
615
|
+
</I18nextProvider>
|
|
616
|
+
</StrictMode>,
|
|
617
|
+
);
|
|
618
|
+
|
|
619
|
+
// After:
|
|
620
|
+
createRoot(document.getElementById('root')!).render(
|
|
621
|
+
wrapJSX(<App />)
|
|
622
|
+
.with(ToasterProvider)
|
|
623
|
+
.with(ThemeProvider, { theme })
|
|
624
|
+
.with(NuqsAdapter)
|
|
625
|
+
.with(QueryClientProvider, { client: queryClient })
|
|
626
|
+
.with(I18nextProvider, { i18n })
|
|
627
|
+
.with(StrictMode)
|
|
628
|
+
.end(),
|
|
629
|
+
);
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
### Parameters
|
|
633
|
+
|
|
634
|
+
<table>
|
|
635
|
+
<thead>
|
|
636
|
+
<tr>
|
|
637
|
+
<th>Parameter</th>
|
|
638
|
+
<th>Type</th>
|
|
639
|
+
<th>Description</th>
|
|
640
|
+
</tr>
|
|
641
|
+
</thead>
|
|
642
|
+
<tbody>
|
|
643
|
+
<tr>
|
|
644
|
+
<td>
|
|
645
|
+
|
|
646
|
+
`jsx`
|
|
647
|
+
|
|
648
|
+
</td>
|
|
649
|
+
<td>
|
|
650
|
+
|
|
651
|
+
`Element`
|
|
652
|
+
|
|
653
|
+
</td>
|
|
654
|
+
<td>
|
|
655
|
+
|
|
656
|
+
The JSX to wrap
|
|
657
|
+
|
|
658
|
+
</td>
|
|
659
|
+
</tr>
|
|
660
|
+
</tbody>
|
|
661
|
+
</table>
|
|
662
|
+
|
|
663
|
+
### Returns
|
|
664
|
+
|
|
665
|
+
[`JSXWrapPipe`](#jsxwrappipe)
|
|
666
|
+
|
|
667
|
+
An object with the following properties:
|
|
668
|
+
|
|
669
|
+
- `with`: a function that accepts a component `Component` and props `props`
|
|
670
|
+
for it as arguments and returns
|
|
671
|
+
`wrapJSX(<Component {...props}>{jsx}</Component>)`
|
|
672
|
+
- `end`: a function that returns `jsx`
|
|
490
673
|
|
|
491
674
|
### See
|
|
492
675
|
|
|
493
|
-
[`
|
|
676
|
+
[`JSXWrapPipe`](#jsxwrappipe)
|
|
494
677
|
|
|
495
678
|
---
|
|
496
679
|
|
|
@@ -502,13 +685,13 @@ type UseEventListener = UseEventListenerWithImplicitWindowTarget &
|
|
|
502
685
|
UseEventListenerWithAnyExplicitTarget;
|
|
503
686
|
```
|
|
504
687
|
|
|
505
|
-
Defined in: [hooks/useEventListener.ts:12](https://github.com/aweebit/react-essentials/blob/v0.
|
|
688
|
+
Defined in: [hooks/useEventListener.ts:12](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useEventListener.ts#L12)
|
|
506
689
|
|
|
507
|
-
The type of [`useEventListener`](#useeventlistener
|
|
690
|
+
The type of [`useEventListener`](#useeventlistener)
|
|
508
691
|
|
|
509
692
|
### See
|
|
510
693
|
|
|
511
|
-
[`useEventListener`](#useeventlistener
|
|
694
|
+
[`useEventListener`](#useeventlistener),
|
|
512
695
|
[`UseEventListenerWithImplicitWindowTarget`](#useeventlistenerwithimplicitwindowtarget),
|
|
513
696
|
[`UseEventListenerWithExplicitGlobalTarget`](#useeventlistenerwithexplicitglobaltarget),
|
|
514
697
|
[`UseEventListenerWithAnyExplicitTarget`](#useeventlistenerwithanyexplicittarget)
|
|
@@ -521,7 +704,7 @@ The type of [`useEventListener`](#useeventlistener-1)
|
|
|
521
704
|
type UseEventListenerWithImplicitWindowTarget = <K>(...args) => void;
|
|
522
705
|
```
|
|
523
706
|
|
|
524
|
-
Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-essentials/blob/v0.
|
|
707
|
+
Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useEventListener.ts#L21)
|
|
525
708
|
|
|
526
709
|
### Type Parameters
|
|
527
710
|
|
|
@@ -573,7 +756,7 @@ Defined in: [hooks/useEventListener.ts:21](https://github.com/aweebit/react-esse
|
|
|
573
756
|
|
|
574
757
|
### See
|
|
575
758
|
|
|
576
|
-
[`useEventListener`](#useeventlistener
|
|
759
|
+
[`useEventListener`](#useeventlistener),
|
|
577
760
|
[`UseEventListenerWithImplicitWindowTargetArgs`](#useeventlistenerwithimplicitwindowtargetargs)
|
|
578
761
|
|
|
579
762
|
---
|
|
@@ -589,11 +772,11 @@ type UseEventListenerWithExplicitGlobalTarget =
|
|
|
589
772
|
UseEventListenerWithExplicitTarget<MathMLElement, MathMLElementEventMap>;
|
|
590
773
|
```
|
|
591
774
|
|
|
592
|
-
Defined in: [hooks/useEventListener.ts:32](https://github.com/aweebit/react-essentials/blob/v0.
|
|
775
|
+
Defined in: [hooks/useEventListener.ts:32](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useEventListener.ts#L32)
|
|
593
776
|
|
|
594
777
|
### See
|
|
595
778
|
|
|
596
|
-
[`useEventListener`](#useeventlistener
|
|
779
|
+
[`useEventListener`](#useeventlistener),
|
|
597
780
|
[`UseEventListenerWithExplicitTarget`](#useeventlistenerwithexplicittarget)
|
|
598
781
|
|
|
599
782
|
---
|
|
@@ -606,7 +789,7 @@ type UseEventListenerWithExplicitTarget<Target, EventMap> = <T, K>(
|
|
|
606
789
|
) => void;
|
|
607
790
|
```
|
|
608
791
|
|
|
609
|
-
Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-essentials/blob/v0.
|
|
792
|
+
Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useEventListener.ts#L44)
|
|
610
793
|
|
|
611
794
|
### Type Parameters
|
|
612
795
|
|
|
@@ -691,7 +874,7 @@ Defined in: [hooks/useEventListener.ts:44](https://github.com/aweebit/react-esse
|
|
|
691
874
|
|
|
692
875
|
### See
|
|
693
876
|
|
|
694
|
-
[`useEventListener`](#useeventlistener
|
|
877
|
+
[`useEventListener`](#useeventlistener),
|
|
695
878
|
[`UseEventListenerWithExplicitTargetArgs`](#useeventlistenerwithexplicittargetargs)
|
|
696
879
|
|
|
697
880
|
---
|
|
@@ -705,11 +888,11 @@ type UseEventListenerWithAnyExplicitTarget = UseEventListenerWithExplicitTarget<
|
|
|
705
888
|
>;
|
|
706
889
|
```
|
|
707
890
|
|
|
708
|
-
Defined in: [hooks/useEventListener.ts:56](https://github.com/aweebit/react-essentials/blob/v0.
|
|
891
|
+
Defined in: [hooks/useEventListener.ts:56](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useEventListener.ts#L56)
|
|
709
892
|
|
|
710
893
|
### See
|
|
711
894
|
|
|
712
|
-
[`useEventListener`](#useeventlistener
|
|
895
|
+
[`useEventListener`](#useeventlistener),
|
|
713
896
|
[`UseEventListenerWithExplicitTarget`](#useeventlistenerwithexplicittarget)
|
|
714
897
|
|
|
715
898
|
---
|
|
@@ -726,7 +909,7 @@ type UseEventListenerWithImplicitWindowTargetArgs<K> =
|
|
|
726
909
|
: never;
|
|
727
910
|
```
|
|
728
911
|
|
|
729
|
-
Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-essentials/blob/v0.
|
|
912
|
+
Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useEventListener.ts#L64)
|
|
730
913
|
|
|
731
914
|
### Type Parameters
|
|
732
915
|
|
|
@@ -749,7 +932,7 @@ Defined in: [hooks/useEventListener.ts:64](https://github.com/aweebit/react-esse
|
|
|
749
932
|
|
|
750
933
|
### See
|
|
751
934
|
|
|
752
|
-
[`useEventListener`](#useeventlistener
|
|
935
|
+
[`useEventListener`](#useeventlistener),
|
|
753
936
|
[`UseEventListenerWithExplicitTargetArgs`](#useeventlistenerwithexplicittargetargs)
|
|
754
937
|
|
|
755
938
|
---
|
|
@@ -771,7 +954,7 @@ type UseEventListenerWithExplicitTargetArgs<EventMap, T, K> = [
|
|
|
771
954
|
];
|
|
772
955
|
```
|
|
773
956
|
|
|
774
|
-
Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-essentials/blob/v0.
|
|
957
|
+
Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/hooks/useEventListener.ts#L78)
|
|
775
958
|
|
|
776
959
|
### Type Parameters
|
|
777
960
|
|
|
@@ -808,21 +991,74 @@ Defined in: [hooks/useEventListener.ts:78](https://github.com/aweebit/react-esse
|
|
|
808
991
|
|
|
809
992
|
### See
|
|
810
993
|
|
|
811
|
-
[`useEventListener`](#useeventlistener
|
|
994
|
+
[`useEventListener`](#useeventlistener)
|
|
812
995
|
|
|
813
996
|
---
|
|
814
997
|
|
|
815
|
-
##
|
|
998
|
+
## ContextualizePipe
|
|
816
999
|
|
|
817
1000
|
```ts
|
|
818
|
-
type
|
|
819
|
-
|
|
820
|
-
|
|
1001
|
+
type ContextualizePipe = {
|
|
1002
|
+
with: ContextualizeWith;
|
|
1003
|
+
end: () => React.JSX.Element;
|
|
1004
|
+
};
|
|
821
1005
|
```
|
|
822
1006
|
|
|
823
|
-
Defined in: [misc/
|
|
1007
|
+
Defined in: [misc/contextualize.tsx:13](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/misc/contextualize.tsx#L13)
|
|
1008
|
+
|
|
1009
|
+
The return type of [`contextualize`](#contextualize)
|
|
1010
|
+
|
|
1011
|
+
### See
|
|
1012
|
+
|
|
1013
|
+
[`contextualize`](#contextualize),
|
|
1014
|
+
[`ContextualizeWith`](#contextualizewith)
|
|
1015
|
+
|
|
1016
|
+
### Properties
|
|
1017
|
+
|
|
1018
|
+
<table>
|
|
1019
|
+
<thead>
|
|
1020
|
+
<tr>
|
|
1021
|
+
<th>Property</th>
|
|
1022
|
+
<th>Type</th>
|
|
1023
|
+
</tr>
|
|
1024
|
+
</thead>
|
|
1025
|
+
<tbody>
|
|
1026
|
+
<tr>
|
|
1027
|
+
<td>
|
|
824
1028
|
|
|
825
|
-
|
|
1029
|
+
<a id="with"></a> `with`
|
|
1030
|
+
|
|
1031
|
+
</td>
|
|
1032
|
+
<td>
|
|
1033
|
+
|
|
1034
|
+
[`ContextualizeWith`](#contextualizewith)
|
|
1035
|
+
|
|
1036
|
+
</td>
|
|
1037
|
+
</tr>
|
|
1038
|
+
<tr>
|
|
1039
|
+
<td>
|
|
1040
|
+
|
|
1041
|
+
<a id="end"></a> `end`
|
|
1042
|
+
|
|
1043
|
+
</td>
|
|
1044
|
+
<td>
|
|
1045
|
+
|
|
1046
|
+
() => `React.JSX.Element`
|
|
1047
|
+
|
|
1048
|
+
</td>
|
|
1049
|
+
</tr>
|
|
1050
|
+
</tbody>
|
|
1051
|
+
</table>
|
|
1052
|
+
|
|
1053
|
+
---
|
|
1054
|
+
|
|
1055
|
+
## ContextualizeWith()
|
|
1056
|
+
|
|
1057
|
+
```ts
|
|
1058
|
+
type ContextualizeWith = <T>(Context, value) => ContextualizePipe;
|
|
1059
|
+
```
|
|
1060
|
+
|
|
1061
|
+
Defined in: [misc/contextualize.tsx:23](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/misc/contextualize.tsx#L23)
|
|
826
1062
|
|
|
827
1063
|
### Type Parameters
|
|
828
1064
|
|
|
@@ -836,48 +1072,125 @@ The return type of [`createSafeContext`](#createsafecontext)
|
|
|
836
1072
|
<tr>
|
|
837
1073
|
<td>
|
|
838
1074
|
|
|
839
|
-
`
|
|
1075
|
+
`T`
|
|
840
1076
|
|
|
841
1077
|
</td>
|
|
842
1078
|
</tr>
|
|
1079
|
+
</tbody>
|
|
1080
|
+
</table>
|
|
1081
|
+
|
|
1082
|
+
### Parameters
|
|
1083
|
+
|
|
1084
|
+
<table>
|
|
1085
|
+
<thead>
|
|
1086
|
+
<tr>
|
|
1087
|
+
<th>Parameter</th>
|
|
1088
|
+
<th>Type</th>
|
|
1089
|
+
</tr>
|
|
1090
|
+
</thead>
|
|
1091
|
+
<tbody>
|
|
843
1092
|
<tr>
|
|
844
1093
|
<td>
|
|
845
1094
|
|
|
846
|
-
`
|
|
1095
|
+
`Context`
|
|
1096
|
+
|
|
1097
|
+
</td>
|
|
1098
|
+
<td>
|
|
1099
|
+
|
|
1100
|
+
`Context`\<`T`\>
|
|
1101
|
+
|
|
1102
|
+
</td>
|
|
1103
|
+
</tr>
|
|
1104
|
+
<tr>
|
|
1105
|
+
<td>
|
|
1106
|
+
|
|
1107
|
+
`value`
|
|
1108
|
+
|
|
1109
|
+
</td>
|
|
1110
|
+
<td>
|
|
1111
|
+
|
|
1112
|
+
`NoInfer`\<`T`\>
|
|
847
1113
|
|
|
848
1114
|
</td>
|
|
849
1115
|
</tr>
|
|
850
1116
|
</tbody>
|
|
851
1117
|
</table>
|
|
852
1118
|
|
|
1119
|
+
### Returns
|
|
1120
|
+
|
|
1121
|
+
[`ContextualizePipe`](#contextualizepipe)
|
|
1122
|
+
|
|
853
1123
|
### See
|
|
854
1124
|
|
|
855
|
-
[`
|
|
856
|
-
[`
|
|
1125
|
+
[`contextualize`](#contextualize),
|
|
1126
|
+
[`ContextualizePipe`](#contextualizepipe)
|
|
857
1127
|
|
|
858
1128
|
---
|
|
859
1129
|
|
|
860
|
-
##
|
|
1130
|
+
## JSXWrapPipe
|
|
861
1131
|
|
|
862
1132
|
```ts
|
|
863
|
-
type
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
displayName: string;
|
|
868
|
-
} & Provider<T>
|
|
869
|
-
: {
|
|
870
|
-
Provider: Provider<T>;
|
|
871
|
-
displayName: string;
|
|
872
|
-
};
|
|
1133
|
+
type JSXWrapPipe = {
|
|
1134
|
+
with: WrapJSXWith;
|
|
1135
|
+
end: () => React.JSX.Element;
|
|
1136
|
+
};
|
|
873
1137
|
```
|
|
874
1138
|
|
|
875
|
-
Defined in: [misc/
|
|
1139
|
+
Defined in: [misc/wrapJSX.tsx:17](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/misc/wrapJSX.tsx#L17)
|
|
1140
|
+
|
|
1141
|
+
The return type of [`wrapJSX`](#wrapjsx)
|
|
876
1142
|
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
[`
|
|
1143
|
+
### See
|
|
1144
|
+
|
|
1145
|
+
[`wrapJSX`](#wrapjsx),
|
|
1146
|
+
[`WrapJSXWith`](#wrapjsxwith)
|
|
1147
|
+
|
|
1148
|
+
### Properties
|
|
1149
|
+
|
|
1150
|
+
<table>
|
|
1151
|
+
<thead>
|
|
1152
|
+
<tr>
|
|
1153
|
+
<th>Property</th>
|
|
1154
|
+
<th>Type</th>
|
|
1155
|
+
</tr>
|
|
1156
|
+
</thead>
|
|
1157
|
+
<tbody>
|
|
1158
|
+
<tr>
|
|
1159
|
+
<td>
|
|
1160
|
+
|
|
1161
|
+
<a id="with-1"></a> `with`
|
|
1162
|
+
|
|
1163
|
+
</td>
|
|
1164
|
+
<td>
|
|
1165
|
+
|
|
1166
|
+
[`WrapJSXWith`](#wrapjsxwith)
|
|
1167
|
+
|
|
1168
|
+
</td>
|
|
1169
|
+
</tr>
|
|
1170
|
+
<tr>
|
|
1171
|
+
<td>
|
|
1172
|
+
|
|
1173
|
+
<a id="end-1"></a> `end`
|
|
1174
|
+
|
|
1175
|
+
</td>
|
|
1176
|
+
<td>
|
|
1177
|
+
|
|
1178
|
+
() => `React.JSX.Element`
|
|
1179
|
+
|
|
1180
|
+
</td>
|
|
1181
|
+
</tr>
|
|
1182
|
+
</tbody>
|
|
1183
|
+
</table>
|
|
1184
|
+
|
|
1185
|
+
---
|
|
1186
|
+
|
|
1187
|
+
## WrapJSXWith()
|
|
1188
|
+
|
|
1189
|
+
```ts
|
|
1190
|
+
type WrapJSXWith = <C>(...args) => JSXWrapPipe;
|
|
1191
|
+
```
|
|
1192
|
+
|
|
1193
|
+
Defined in: [misc/wrapJSX.tsx:27](https://github.com/aweebit/react-essentials/blob/v0.10.1/src/misc/wrapJSX.tsx#L27)
|
|
881
1194
|
|
|
882
1195
|
### Type Parameters
|
|
883
1196
|
|
|
@@ -891,13 +1204,43 @@ as an argument to `useContext` or `use` (the hook produced with
|
|
|
891
1204
|
<tr>
|
|
892
1205
|
<td>
|
|
893
1206
|
|
|
894
|
-
`
|
|
1207
|
+
`C` _extends_ keyof `JSX.IntrinsicElements` \| `JSXElementConstructor`\<`any`\>
|
|
1208
|
+
|
|
1209
|
+
</td>
|
|
1210
|
+
</tr>
|
|
1211
|
+
</tbody>
|
|
1212
|
+
</table>
|
|
1213
|
+
|
|
1214
|
+
### Parameters
|
|
1215
|
+
|
|
1216
|
+
<table>
|
|
1217
|
+
<thead>
|
|
1218
|
+
<tr>
|
|
1219
|
+
<th>Parameter</th>
|
|
1220
|
+
<th>Type</th>
|
|
1221
|
+
</tr>
|
|
1222
|
+
</thead>
|
|
1223
|
+
<tbody>
|
|
1224
|
+
<tr>
|
|
1225
|
+
<td>
|
|
1226
|
+
|
|
1227
|
+
...`args`
|
|
1228
|
+
|
|
1229
|
+
</td>
|
|
1230
|
+
<td>
|
|
1231
|
+
|
|
1232
|
+
\[`C`, `...(Record<never, unknown> extends Omit<ComponentProps<C>, "children"> ? [props?: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">] : [props: React.JSX.IntrinsicAttributes & Omit<ComponentProps<C>, "children">])`\]
|
|
895
1233
|
|
|
896
1234
|
</td>
|
|
897
1235
|
</tr>
|
|
898
1236
|
</tbody>
|
|
899
1237
|
</table>
|
|
900
1238
|
|
|
1239
|
+
### Returns
|
|
1240
|
+
|
|
1241
|
+
[`JSXWrapPipe`](#jsxwrappipe)
|
|
1242
|
+
|
|
901
1243
|
### See
|
|
902
1244
|
|
|
903
|
-
[`
|
|
1245
|
+
[`wrapJSX`](#wrapjsx),
|
|
1246
|
+
[`JSXWrapPipe`](#jsxwrappipe)
|