9 | 2 10 |
11 | 14 |= (props: PropsWithChildren
) => StageRender | ReactElement | null 5 | type StageRenderRootWithRef
= (props: PropsWithChildren
, ref: Ref (props: {
18 | stage: StageRender
19 | }) {
20 | const next = props.stage()
21 | return processNext(next)
22 | }
23 |
24 | export function staged (
25 | stage: StageRenderRoot
26 | ): FC
27 | export function staged (
28 | stage: StageRenderRootWithRef ,
29 | ): RefForwardingComponent (
31 | stage: StageRenderRootWithRef ,
32 | ) {
33 | return function Staged(props, ref) {
34 | const next = stage(props, ref)
35 | return processNext(next)
36 | } as FC
37 | }
38 |
--------------------------------------------------------------------------------
/src/__tests__/main.test.tsx:
--------------------------------------------------------------------------------
1 | import {act} from '@testing-library/react'
2 | import {staged} from '..'
3 | import * as React from 'react'
4 | import {forwardRef, useEffect, useImperativeHandle, useState} from 'react'
5 | import * as testing from '@testing-library/react'
6 |
7 | export const sleep = (time: number) => new Promise(resolve => setTimeout(resolve, time))
8 |
9 | test('provider initialize', async function () {
10 | const App = staged(() => {
11 | const [waiting, setWaiting] = useState(true)
12 | useEffect(() => {
13 | setTimeout(() => {
14 | act(() => {
15 | setWaiting(false)
16 | })
17 | }, 300)
18 | }, [])
19 | if (waiting) return null
20 | return () => {
21 | const [count, setCount] = useState(1)
22 | return (
23 | {count}{props.user.name}
55 | )
56 | }
57 | }))
58 | ```
59 |
60 | ```tsx
61 | type Props = {};
62 | type Ref = {};
63 | const App = forwardRef(
64 | staged{props.user.name}
;
69 | };
70 | })
71 | );
72 | ```
73 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /lib/
2 |
3 | # Webstorm
4 | ## User-specific stuff
5 | .idea/**/workspace.xml
6 | .idea/**/tasks.xml
7 | .idea/**/usage.statistics.xml
8 | .idea/**/dictionaries
9 | .idea/**/shelf
10 | ## Generated files
11 | .idea/**/contentModel.xml
12 | # Sensitive or high-churn files
13 | .idea/**/dataSources/
14 | .idea/**/dataSources.ids
15 | .idea/**/dataSources.local.xml
16 | .idea/**/sqlDataSources.xml
17 | .idea/**/dynamic.xml
18 | .idea/**/uiDesigner.xml
19 | .idea/**/dbnavigator.xml
20 |
21 | # Logs
22 | logs
23 | *.log
24 | npm-debug.log*
25 | yarn-debug.log*
26 | yarn-error.log*
27 |
28 | # Runtime data
29 | pids
30 | *.pid
31 | *.seed
32 | *.pid.lock
33 |
34 | # Directory for instrumented libs generated by jscoverage/JSCover
35 | lib-cov
36 |
37 | # Coverage directory used by tools like istanbul
38 | coverage
39 |
40 | # nyc test coverage
41 | .nyc_output
42 |
43 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
44 | .grunt
45 |
46 | # Bower dependency directory (https://bower.io/)
47 | bower_components
48 |
49 | # node-waf configuration
50 | .lock-wscript
51 |
52 | # Compiled binary addons (https://nodejs.org/api/addons.html)
53 | build/Release
54 |
55 | # Dependency directories
56 | node_modules/
57 | jspm_packages/
58 |
59 | # TypeScript v1 declaration files
60 | typings/
61 |
62 | # Optional npm cache directory
63 | .npm
64 |
65 | # Optional eslint cache
66 | .eslintcache
67 |
68 | # Optional REPL history
69 | .node_repl_history
70 |
71 | # Output of 'npm pack'
72 | *.tgz
73 |
74 | # Yarn Integrity file
75 | .yarn-integrity
76 |
77 | # dotenv environment variables file
78 | .env
79 |
80 | # next.js build output
81 | .next
82 |
83 | ### macOS ###
84 | # General
85 | .DS_Store
86 | .AppleDouble
87 | .LSOverride
88 |
89 | # Icon must end with two \r
90 | Icon
91 |
92 | # Thumbnails
93 | ._*
94 |
95 | # Files that might appear in the root of a volume
96 | .DocumentRevisions-V100
97 | .fseventsd
98 | .Spotlight-V100
99 | .TemporaryItems
100 | .Trashes
101 | .VolumeIcon.icns
102 | .com.apple.timemachine.donotpresent
103 |
104 | # Directories potentially created on remote AFP share
105 | .AppleDB
106 | .AppleDesktop
107 | Network Trash Folder
108 | Temporary Items
109 | .apdisk
110 |
--------------------------------------------------------------------------------