question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(react-split): How to handle conditional children

See original GitHub issue

I’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:open
  • Created a year ago
  • Reactions:1
  • Comments:10

github_iconTop GitHub Comments

1reaction
martinsvbcommented, Jul 1, 2022

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:

at SplitWrapper (http://localhost:3000/static/js/bundle.js:178736:16)
at Items (http://localhost:3000/static/js/bundle.js:78293:77)
at Outlet (http://localhost:3000/static/js/bundle.js:178553:26)
at div
at http://localhost:3000/static/js/bundle.js:80768:66
at Container (http://localhost:3000/static/js/bundle.js:94477:82)
at main
at http://localhost:3000/static/js/bundle.js:80768:66
at Content (http://localhost:3000/static/js/bundle.js:83142:5)
at Root (http://localhost:3000/static/js/bundle.js:85300:19)
at http://localhost:3000/static/js/bundle.js:77513:77
at Routes (http://localhost:3000/static/js/bundle.js:178645:5)
at Router (http://localhost:3000/static/js/bundle.js:178578:15)
at BrowserRouter (http://localhost:3000/static/js/bundle.js:177387:5)
at I18nextProvider (http://localhost:3000/static/js/bundle.js:174018:19)
at LocalisationProvider (http://localhost:3000/static/js/bundle.js:78033:5)
at SnackbarProvider (http://localhost:3000/static/js/bundle.js:142916:24)
at InnerThemeProvider (http://localhost:3000/static/js/bundle.js:111896:70)
at ThemeProvider (http://localhost:3000/static/js/bundle.js:111598:5)
at ThemeProvider (http://localhost:3000/static/js/bundle.js:111916:5)
at MuiProviders (http://localhost:3000/static/js/bundle.js:78117:5)
at Provider (http://localhost:3000/static/js/bundle.js:174711:5)

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.

1reaction
addycommented, Jun 1, 2022

At first glance that looks a lot like what I had in mind, I wasn’t sure if we needed to call this.split.destroy with true, false to not preserve the gutter.

I’ll see if I can’t find that proptype issue!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found