TypeError: Cannot read properties of null (reading 'slideReset')

I am using swiper in react. I want to reset the swiper and return to the first page of the carousel.

Below is my code

import { Swiper, SwiperSlide, useSwiper } from 'swiper/react/swiper-react.js';
const swiper = useSwiper();
const swiperRe = () => {
    swiper.slideReset();
}

But I am getting below error-

TypeError: Cannot read properties of null (reading ' slideReset').