akiran / akiran/react-slick

Get offsetWidth of element in slick-track

Open
#2,381 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
11.9k
Forks
2.1k
PR merge metrics
No merged PRs in 30d

Description

### Guidelines for posting a new issue
I wanna get width of the first elem in slick-track. It oke in local but not working in env product when I resize window to mobile (for web) and mobile device

Uncaught TypeError: Cannot read properties of null (reading 'offsetWidth')
at HorizontalCarouselComponent.tsx:52:69
at Bm (react-dom.production.min.js:244:332)
at Oc (react-dom.production.min.js:286:111)
at q$ (react-dom.production.min.js:283:409)
at ml (react-dom.production.min.js:281:398)
at U0 (react-dom.production.min.js:273:439)
at Xs (react-dom.production.min.js:127:105)
at react-dom.production.min.js:267:273
And this is my code
``` typescript
const slideRef = useRef(null)

useEffect(() => {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (slideRef.current && isMobile) {
setWidthSlider(
Number(
slideRef.current.innerSlider.track.node.firstElementChild.offsetWidth // get width of the first elem in list slider
)
)
}
}, [slideRef.current, window.innerWidth, isMobile])

{
setCurrentIndex(currentSlide)
}}
>
{children}

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.