File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -199,7 +199,7 @@ class OutPortal<C extends Component<any>> extends React.PureComponent<OutPortalP
199199
200200 // If we're switching portal nodes, we need to clean up the current one first.
201201 if ( this . currentPortalNode && node !== this . currentPortalNode ) {
202- this . currentPortalNode . unmount ( ) ;
202+ this . currentPortalNode . unmount ( this . placeholderNode . current ! ) ;
203203 this . currentPortalNode = node ;
204204 }
205205
Original file line number Diff line number Diff line change @@ -226,6 +226,40 @@ storiesOf('Portals', module)
226226 < Parent />
227227 </ div > ;
228228 } )
229+ . add ( "swap nodes between different locations" , ( ) => {
230+ const numberOfNodes = 5 ;
231+ const initialOrder = [ ] ;
232+ for ( let i = 0 ; i < numberOfNodes ; i ++ ) {
233+ initialOrder [ i ] = i ;
234+ }
235+
236+ const ExampleContent = ( { content } ) => String ( content ) ;
237+
238+ const ChangeLayoutWithoutUnmounting = ( ) => {
239+ const nodes = React . useMemo (
240+ ( ) => initialOrder . map ( createHtmlPortalNode ) ,
241+ [ ]
242+ ) ;
243+ const [ order , setOrder ] = React . useState ( initialOrder ) ;
244+ return (
245+ < div >
246+ < button onClick = { ( ) => setOrder ( order . slice ( ) . reverse ( ) ) } >
247+ Click to reverse the order
248+ </ button >
249+ { nodes . map ( ( node , index ) => (
250+ < InPortal node = { node } >
251+ < ExampleContent content = { index } />
252+ </ InPortal >
253+ ) ) }
254+ { order . map ( ( position ) => (
255+ < OutPortal node = { nodes [ position ] } />
256+ ) ) }
257+ </ div >
258+ ) ;
259+ } ;
260+
261+ return < ChangeLayoutWithoutUnmounting /> ;
262+ } )
229263 . add ( 'Example from README' , ( ) => {
230264 const MyExpensiveComponent = ( ) => 'expensive!' ;
231265
You can’t perform that action at this time.
0 commit comments