N
Nuxt7mo ago
NABI

Please help my issue

const useSlideRefs = (slideCount: number) => {
const refs = useRef<Array<React.RefObject<any> | null>>([]);
useEffect(() => {
refs.current = Array(slideCount)
.fill(null)
.map((_, i) => refs.current[i] || React.createRef());
}, [slideCount]);
return refs.current;
};

const slidesRefs = useSlideRefs(slideCount);
console.log(slidesRefs);

const onResize = (): void => {
const newSlideAnchors = calculateAnchors(slidesRefs, gridGap, isInfinite);
};

useEffect(() => {
onResize();
}, []);
const useSlideRefs = (slideCount: number) => {
const refs = useRef<Array<React.RefObject<any> | null>>([]);
useEffect(() => {
refs.current = Array(slideCount)
.fill(null)
.map((_, i) => refs.current[i] || React.createRef());
}, [slideCount]);
return refs.current;
};

const slidesRefs = useSlideRefs(slideCount);
console.log(slidesRefs);

const onResize = (): void => {
const newSlideAnchors = calculateAnchors(slidesRefs, gridGap, isInfinite);
};

useEffect(() => {
onResize();
}, []);
This is my react typescript code. slidesRefs returns empty array in onResize() function even though it shows the result in console. because it takes time to fill that array, I think. How to solve this? I wanna get the filled array(not filled with null). please help me
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server