NABI
NABI
NNuxt
Created by NABI on 6/20/2024 in #❓・help
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
1 replies