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.

[XYChart] <BarGroup> breaks when children are <React.Fragment>s

See original GitHub issue

For reasons to do with accessing data from our redux store, I would like to have my <BarSeries> inside of a function component.

Unfortunately, the library will try to look at the < DataSetBar> component as the series it expects, then throw when the entry’s data is undefined.

Is there any way to work around this?

Here is my code (abridged):

function DataGroupBar({ dataGroup }) {
  return (
    <AnimatedBarGroup>
      {dataGroup.map((dataSet) => (
        <DataSetBar
          key={dataSet.rowId}
          dataSet={dataSet}
        />
      ))}
    </AnimatedBarGroup>
  )
}

function DataSetBar({ dataSet }) {
  const { rowId, color } = dataSet
  const reportItem = useSelector((state) => state.reports[rowId])

  const actualsData = dateRange.map((month) => ({
      x: dateParser(month),
      y: computeBalance(reportItem),
    }))

  const budgetsData = dateRange.map((month) => ({
      x: dateParser(month),
      y: computeBalance(reportItem),
    }))

  return (
    <>
      <AnimatedBarSeries
        dataKey={`${reportItem.name} Actuals`}
        data={actualsData}
        {...accessors}
      />

      <AnimatedBarSeries
        dataKey={`${reportItem.name} Budgets`}
        data={budgetsData}
        {...accessors}
      />
    </>
  )
}

Right now, the only way I can see here is to move everything into my <DataGroupBar> component, forcing me to access all of state.reports in redux which loses performance as it causes a re-render every time any row in there changes, opposed to accessing just the single row.

I feel like the library should be able to tell that <DataSetBar> resolves into 2 <AnimatedBarSeries> and access them directly.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
williastercommented, Feb 2, 2021

Yeah this is because the <BarGroup /> expects its direct children to be <BarSeries />. Messing with / traversing children in React is a bit gross but seems like we should be able to create a helper function to traverse until a BarSeries component is found. Will try to look into this this week but don’t have a ton of bandwidth.

0reactions
tonyneel923commented, Jun 29, 2021

I am running into this problem when dynamically generating bar series for a bar group and am not sure how to get around it.

Example code

<BarGroup padding={0}>
          {barChartsCollection.items.map((barChart) => {
            const vertical = xScale?.type === 'band';
            const { xAxis: currentXAxis, yAxis: currentYAxis } = barChart;
            return (
              <AnimatedBarSeries
                key={barChart.sys.id}
                dataKey={vertical ? currentYAxis : currentXAxis}
                data={items}
                xAccessor={(d: object) => vertical ? getLocValue(schema, d, currentXAxis) : getLocValue(schema, d, currentYAxis)}
                yAccessor={(d: object) => vertical ? getLocValue(schema, d, currentYAxis) : getLocValue(schema, d, currentXAxis)}
              />
            )
          })}
        </BarGroup>
Read more comments on GitHub >

github_iconTop Results From Across the Web

React.Children.map ambiguous behavior with Fragments
Children.map recursively go through Array children, but does not "penetrate" into Fragments? reactjs.
Read more >
Changelog - GitHub
Fragment`, dropping support for `react@^15` - Empty parent `<g>` wrapper around Drag `children` was replaced with a `React.Fragment` which removes a DOM ...
Read more >
Rendering child elements in React using Fragments
One of the advantages of using React to render a user interface is that it's easy to break up the UI into components....
Read more >
www.allitebooks.com
Binding usually refers to the ability to automatically react and ... It applies its algorithm to all children in its content property when...
Read more >
Untitled
In the Display Builder the following changes have been made to the Alert Dialog: The Filters panel has been relocated below the Alerts...
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