TypeScript Error when putting Chart inside of ResponsiveContainer
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
Put a Chart inside of a ResponsiveContainer - see also codesandbox
–> TypeScript Error in ChartUtils.js:86
at calculateActiveTickIndex
What is expected?
No Error
What is actually happening?
I really cant tell because i am new to recharts. I tried with version 2.0.0, 2.0.1 and 2.0.2 I cant even run the examle codes provided on recharts.org inside of a ResponsiveContainer I get a TypeError: Cannot read property ‘length’ of undefined
Environment | Info |
---|---|
Recharts | v2.0.2 |
React | tested with 16.14 and 17.0.0 |
System | Windows 10 |
Browser | Chrome |
I made a very short codesandbox to reproduce: https://codesandbox.io/s/recharts-typescript-error-4mtpq
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Recharts Responsive Container does not resize correctly ...
Clarification: The problem is that when I close and then open the legend, the legend component gets pushed out of the viewing area...
Read more >Recharts
Quickly build your charts with decoupled, reusable React components. Reliable. Built on top of SVG elements with a lightweight dependency on D3 submodules....
Read more >CHANGELOG.md · Gitee 极速下载/recharts - Gitee.com
Allowing length in different unit in ResponsiveContainer By allowing type: String on 'minHeight', 'minWidth', 'maxHeight' property, developers can use length in ...
Read more >recharts | Yarn - Package Manager
Recharts is a Redefined chart library built with React and D3. The main purpose of this library is to help you to write...
Read more >Build and Custom Style Recharts Data Charts
We'll get into this more when we create the tooltip component, so put a pin in this for now. ResponsiveContainer wraps the whole...
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
I am having the same issue as @raRaRa. The error appears to be coming from
calculateActiveTickIndex
…Note: for me it only appears in my Jest tests when after the component has mounted I change what is being passed to
data
(BarChart
) usingsetProps()
. Whether or not the contents of the array change doesn’t seem to matter. Instead, it seems that an error is thrown when the reference to the array is changed (a new array is passed to thedata
prop).It appears that this results in the ticks passed to
calculateActiveTickIndex
to be undefined, leading to the error as pointed out by @raRaRa. Note that my tests used to pass on Recharts version 1.8.5. It stopped working after upgrading to 2.0.3.Also, I have tried it without the ResponsiveContainer, but the error persists…
React: 16.14.0
+1, removing
<ResponsiveContainer>
doesn’t change anything. The issue still appears in our Jest tests