문제
const candleSeriesApiRef = React.useRef<ISeriesApi<'Candlestick'> | null>(null);
...
...
...
candleSeriesApiRef.current.update(currentBar);
//'candleSeriesApiRef.current' is possibly 'null'.
해결방법
- if문
if(candleSeriesApiRef.current){ candleSeriesApiRef.current.update(currentBar); }
- if문으로 null을 걸러냄
- ! 사용(non-null assertion operator)
candleSeriesApiRef.current!.update(currentBar);
- typescript 내에서 ! 사용은 해당 value가 null 이나 undefined이 아니라는 확증
'React' 카테고리의 다른 글
| [React] setState를 동기적으로 작동하게 만들기(feat. flushSync) (0) | 2023.09.08 |
|---|---|
| [React, TypeScript] 실시간 시세표 일정 시간만 border 노출하기 (0) | 2023.09.08 |
| [React, Spring Boot] Whitelabel Error Page문제 (0) | 2023.09.07 |
| [React, TypeScript] TradingView lightweight-charts 사용 (0) | 2023.09.07 |
| [React] JS Bites: React hook is called in a function which is neither a React function or a custom React Hook (0) | 2023.09.07 |