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.

Chart components do not render when wrapped in custom components

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Open my minimal reproduction link

What is expected?

YAxis is displayed

What is actually happening?

YAxis is not displayed

Environment Info
Recharts v2.1.6
React 17.0.2
System Mac
Browser Chrome

I want to wrap chart components (like YAxis) up in my own components. I want to do this so that I can set some default behavior in my wrapper and then pass in some customisations.

For example

export const YAxisWrapper: React.FC<Props> = ({dataKey, label}) => (
  <YAxis dataKey={dataKey} allowDecimals={false} tick={tick}>
    <Label
      value={label}
      position='left'
      angle={-90}
      style={{ textAnchor: 'middle' }}
      offset={-25}
    />
  </YAxis>
);

However when I wrap rechats components up into my own components they are no longer displayed in the chart.

I have created a very simple sandbox example here. https://codesandbox.io/s/simple-bar-chart-forked-8f3jgg?file=/src/App.tsx

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

1reaction
jake-danielscommented, Dec 15, 2022

@xile611 This issue is open for a quite long time now without any response from maintainers. Kind of a red flag.

@gsipos You can still create reusable pieces by creating function that returns JSX markup and then calling it in the “parent” markup.

function renderXAxis(params) {
   return (
      <some-markup>
   )
}   

// parent scope
return (
   <div>
      {renderXAxis(params)}
   </div>
)

But this approach lacks all the features of react component.

0reactions
gsiposcommented, Dec 14, 2022

This is particularly painful because it makes hard to reuse bits and pieces between chart components, and I feel like I’m forced to repeat myself. For example I’m creating multiple variations of bar charts, that have basically everything(axis, tooltip, bars) styled according to app design, but the variants have a lot in common.

I’ve encountered this issue with XAxis, YAxis, Tooltip.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I have a component that doesn't render a pseudo-element?
The user of the component then has full control over how each column is rendered - including what classes are applied to the...
Read more >
5 Ways to Avoid React Component Re-Renderings
As a solution, you can use React Fragments to wrap the components, and it will reduce the load on the DOM, resulting in...
Read more >
Troubleshooting Guide - React Flow
A possible solution is to wrap your component with a <ReactFlowProvider /> or ... is missing, so React Flow cannot find the custom...
Read more >
ASP.NET Core Razor components - Microsoft Learn
Methods for user event handling, lifecycle events, and custom component logic. Component members are used in rendering logic using C# ...
Read more >
Docs • Svelte
Reactive statements run after other script code and before the component markup is rendered, whenever the values that they depend on have changed....
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