(react-split): How to handle conditional children
See original GitHub issueI’ve got an issue where the entire Split system isn’t being initialized (no gutter present) if the second of my two children is being conditionally rendered.
My second child is rendered asynchronously based on some logic, I would like for the Split system to initialize with the gutter once the second child is rendered.
Basic example would look like this:
<Split>
<ComponentA />
{shouldRender && (
<ComponentB />
)}
</Split>
Is it possible to do the above without having to do something like this:
<>
{shouldRender ? (
<Split>
<ComponentA />
<ComponentB />
</Split>
) : (
<ComponentA />
)}
</>
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:10
Top Results From Across the Web
Conditional Rendering - React
You can use variables to store elements. This can help you conditionally render a part of the component while the rest of the...
Read more >React conditional rendering: 9 methods with examples
In React, conditional rendering refers to the process of delivering elements and components based on certain conditions.
Read more >React Children And Iteration Methods - Smashing Magazine
In this article, we'll discuss and learn about the use case of iterating over React `children` and the ways to do it. In...
Read more >How to have conditional elements and keep DRY with ...
What about this. Let's define a simple helping If component. var If = React.createClass({ render ...
Read more >React children composition patterns with TypeScript - Medium
Leveraging TypeScript with well known React children composition ... get excellent developer experience and type-safety along the process.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’m encounter similar issue. We have initial screen with 1 split view and sizes: [100]. There is requirement dynamical split view adding / removing. So, if I add second split view and sets sizes prop: [50, 50] dynamically, error is thrown. Console error:
split.es.js:719 Uncaught TypeError: Cannot read properties of undefined (reading 'a') at split.es.js:719:1 at Array.forEach (<anonymous>) at Object.setSizes (split.es.js:715:1) at SplitWrapper.componentDidUpdate (react-split.es.js:108:1) at commitLayoutEffectOnFiber (react-dom.development.js:23232:1) at commitLayoutMountEffects_complete (react-dom.development.js:24578:1) at commitLayoutEffects_begin (react-dom.development.js:24564:1) at commitLayoutEffects (react-dom.development.js:24502:1) at commitRootImpl (react-dom.development.js:26779:1) at commitRoot (react-dom.development.js:26638:1)`react_devtools_backend.js:4026 The above error occurred in the <SplitWrapper> component:
Consider adding an error boundary to your tree to customize error handling behavior. Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.`
There is probabably problem, that Split parent component operates with new sizes array over previous element settings and can’t find new split elements added as children.
At first glance that looks a lot like what I had in mind, I wasn’t sure if we needed to call
this.split.destroywithtrue, falseto not preserve the gutter.I’ll see if I can’t find that proptype issue!