1
- import React , { useMemo , useCallback , memo , useState , useEffect } from 'react' ;
1
+ import React , { useCallback , memo , useMemo } from 'react' ;
2
2
import {
3
3
path ,
4
4
concat ,
@@ -43,19 +43,13 @@ type DashWrapperProps = {
43
43
_dashprivate_error ?: any ;
44
44
} ;
45
45
46
- // Define the type for your state
47
- type HydratedState = React . DetailedReactHTMLElement <
48
- React . InputHTMLAttributes < HTMLInputElement > ,
49
- HTMLInputElement
50
- > | null ;
51
46
52
47
function DashWrapper ( {
53
48
componentPath,
54
49
_dashprivate_error,
55
50
...extras
56
51
} : DashWrapperProps ) {
57
52
const dispatch = useDispatch ( ) ;
58
- const [ hydrated , setHydrated ] = useState < HydratedState > ( null ) ;
59
53
60
54
// Get the config for the component as props
61
55
const config : DashConfig = useSelector ( selectConfig ) ;
@@ -66,22 +60,6 @@ function DashWrapper({
66
60
selectDashPropsEqualityFn
67
61
) ;
68
62
69
- const dependenciesStable = useMemo ( ( ) => {
70
- return JSON . stringify (
71
- {
72
- h,
73
- componentPath,
74
- componentProps
75
- }
76
- )
77
- } , [
78
- JSON . stringify ( {
79
- componentProps,
80
- componentPath,
81
- h
82
- } )
83
- ] )
84
-
85
63
const setProps = ( newProps : UpdatePropsPayload ) => {
86
64
const { id} = componentProps ;
87
65
const { _dash_error, ...restProps } = newProps ;
@@ -393,44 +371,33 @@ function DashWrapper({
393
371
return props ;
394
372
} ;
395
373
396
- useEffect ( ( ) => {
397
- let comp ;
374
+ const hydrated = useMemo ( ( ) => {
398
375
if ( ! component ) {
399
- return
376
+ return ;
400
377
}
378
+
401
379
const element = Registry . resolve ( component ) ;
402
- const hydratedProps = setHydratedProps ( )
380
+ const hydratedProps = setHydratedProps ( ) ;
381
+
403
382
let hydratedChildren : any ;
404
383
if ( componentProps . children !== undefined ) {
405
- hydratedChildren = wrapChildrenProp ( componentProps . children , [
406
- 'children'
407
- ] ) ;
408
- }
409
- if ( config . props_check ) {
410
- comp = (
411
- < CheckedComponent
412
- element = { element }
413
- props = { hydratedProps }
414
- component = { component }
415
- >
416
- { createElement (
417
- element ,
418
- hydratedProps ,
419
- extraProps ,
420
- hydratedChildren
421
- ) }
422
- </ CheckedComponent >
423
- ) ;
384
+ hydratedChildren = wrapChildrenProp ( componentProps . children , [ 'children' ] ) ;
424
385
}
425
386
426
- comp = createElement (
427
- element ,
428
- hydratedProps ,
429
- extraProps ,
430
- hydratedChildren
387
+ const rendered = config . props_check ? (
388
+ < CheckedComponent
389
+ element = { element }
390
+ props = { hydratedProps }
391
+ component = { component }
392
+ >
393
+ { createElement ( element , hydratedProps , extraProps , hydratedChildren ) }
394
+ </ CheckedComponent >
395
+ ) : (
396
+ createElement ( element , hydratedProps , extraProps , hydratedChildren )
431
397
) ;
432
- setHydrated ( comp )
433
- } , [ dependenciesStable ] ) ;
398
+
399
+ return rendered
400
+ } , [ h ] ) ;
434
401
435
402
if ( ! component ) {
436
403
return null
@@ -448,7 +415,7 @@ function DashWrapper({
448
415
dispatch = { dispatch }
449
416
>
450
417
< DashContextProvider componentPath = { componentPath } >
451
- { hydrated ? hydrated : < > < /> }
418
+ { hydrated ? hydrated : < div /> }
452
419
</ DashContextProvider >
453
420
</ ComponentErrorBoundary >
454
421
) ;
0 commit comments