Comments (4)
Hi, for cases like this when you have some race conditions, we suggest you use React.useRef
to check if the component is still mounted.
const isMounted = useRef(true);
useEffect(
() => {
const chart = createChart(chartContainerRef.current, chartOptions)
candles = await fetchCandles()
if (isMounted.current) {
// Do whatever you want to do with chart
const mainSeries = chart.addCandlestickSeries(candles)
}
return () => {
window.removeEventListener('resize', handleResize);
isMounted.current = false;
chart.remove();
};
},
[deps]
);
Also, you could use AbortController to prevent fetching the data if the component is already unmounted
from lightweight-charts.
The library is client-side only, so you shouldn't render it on the server;
i'm not rendering on the server, on the server i show a "skeleton"
in the case of the modern Next.js, you should use the
'use client'
directive. Regarding accessing some properties afterremove()
, we don't have plans to change the current behavior, at least in the near future.
thank you, your suggestions and explanations were very helpful.
from lightweight-charts.
Hi, for cases like this when you have some race conditions, we suggest you use
React.useRef
to check if the component is still mounted.
Also, you could use AbortController to prevent fetching the data if the component is already unmounted
Thanks for the suggestions @illetid definitely more elegant than my ['isRemoving']
hack.
Still, due the fact this happens with the most basic react example on the documentation when used on Next.js ( due to the re-render nature of hydration, etcs ) wouldn't it make sense to have the library not trying to read some _internal*
variable after the remove()
method has been called?
from lightweight-charts.
The library is client-side only, so you shouldn't render it on the server; in the case of the modern Next.js, you should use the 'use client'
directive. Regarding accessing some properties after remove()
, we don't have plans to change the current behavior, at least in the near future.
from lightweight-charts.
Related Issues (20)
- Uncaught TypeError TypeError: Cannot read properties of undefined (reading '_internal_state') HOT 1
- The curve and time axis jitter when moving left HOT 5
- Series title obfuscates the chart line HOT 2
- Delta Tooltip Plugin HOT 1
- Build is broken: Puppeteer download URL access denied HOT 2
- missing very small numbers HOT 8
- Optimize the algorithm for curved line
- No possibility to install as github dependency. Postinstall hook is missed. HOT 1
- Unable to display the real-time price of priceLine on the price axis HOT 3
- How to add floating data info (OHLCV) on corner for the hovored day ? HOT 2
- Is it possible to real-time update chart per minute and not per day? HOT 1
- Is it possible to show weekly data, depending on daily data ? HOT 2
- Issue with Weight Calculation for Second Rendered Label on Time Axis HOT 3
- Current Price Tag Not Displayed HOT 1
- Crosshair vertLine doesn't match with tickMarkFormatter HOT 2
- Keep Order Lines Always on Top in TradingView Charts Library HOT 3
- SubscribeCrosshairMove incorrect cordinates
- Key "zb" is being added to javascript object HOT 3
- [Typescript] WhitespaceData value typescript error HOT 1
- Assertion failed: data must be asc ordered by time. TIME DIPLICATES HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightweight-charts.