File tree Expand file tree Collapse file tree 4 files changed +155
-128
lines changed Expand file tree Collapse file tree 4 files changed +155
-128
lines changed Original file line number Diff line number Diff line change 8888 "lint-staged" : " ^10.2.13" ,
8989 "react" : " 16.14.0" ,
9090 "react-dom" : " 16.14.0" ,
91- "stan-builder" : " ^0.11.1 " ,
91+ "stan-builder" : " ^0.11.3 " ,
9292 "standard-version" : " ^9.0.0" ,
9393 "ts-jest" : " ^27.0.3" ,
9494 "typescript" : " 4.1.5"
Original file line number Diff line number Diff line change 1- import React , { HTMLAttributes } from 'react' ;
1+ import React from 'react' ;
22import ReactDOM from 'react-dom' ;
33
44export type CacheComponentDOMProps = React . PropsWithChildren < {
@@ -20,7 +20,7 @@ export type CacheComponentDOMProps = React.PropsWithChildren<{
2020 /**
2121 * 包裹元素props
2222 */
23- containerHTMLProps ?: HTMLAttributes < any > ;
23+ containerHTMLProps ?: React . HTMLAttributes < any > ;
2424} > ;
2525
2626/**
@@ -41,12 +41,13 @@ function CacheComponentDOM(props: CacheComponentDOMProps) {
4141 const [ container ] = React . useState ( getContainer ) ;
4242 const hasUpdate = shouldUpdate ( ) ;
4343
44+ const divRef = React . useRef ( document . createElement ( 'div' ) ) ;
45+
4446 React . useLayoutEffect (
4547 ( ) => {
4648 moveChildNode ( container , elRef . current ! ) ;
47- const div = document . createElement ( 'div' ) ;
48- ReactDOM . render ( children as React . ReactElement , div , ( ) => {
49- elRef . current ! . innerHTML = div . innerHTML ;
49+ ReactDOM . render ( children as React . ReactElement , divRef . current , ( ) => {
50+ elRef . current ! . innerHTML = divRef . current . innerHTML ;
5051 } ) ;
5152 return ( ) => {
5253 container . innerHTML = '' ;
Original file line number Diff line number Diff line change @@ -70,19 +70,19 @@ function makeGlobalApi<P = any>(opts: MakeGlobalApiOptions<P>): MakeGlobalApiRet
7070 ReactDOM . render ( < Wrapper ref = { wrapperRef } /> , div ) ;
7171
7272 return {
73- render ( props ?: any ) {
73+ render ( props ?: P ) {
7474 const index = wrapperRef . current ?. add ( children , props ) ! ;
7575 return {
7676 index,
7777 unmount ( ) {
7878 return wrapperRef . current ?. del ( index ) ;
7979 } ,
80- update ( props : any ) {
80+ update ( props : P ) {
8181 wrapperRef . current ?. update ( index , props ) ;
8282 } ,
8383 } ;
8484 } ,
85- update ( key , props ?: any ) {
85+ update ( key , props ?: P ) {
8686 wrapperRef . current ?. update ( key , props ) ;
8787 } ,
8888 unmountAll ( ) {
You can’t perform that action at this time.
0 commit comments