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
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:
- Created 2 years ago
- Reactions:8
- Comments:5
Top 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 >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 FreeTop 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
Top GitHub Comments
@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.
But this approach lacks all the features of react component.
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.