Skip to content Skip to sidebar Skip to footer

Call Js Function From Another File In React?

I have a function in a separate JavaScript file that I would like to call in a React component - how can I achieve this? I'm trying to create a slideshow, and in slideshow.js, I ha

Solution 1:

You can export it, or am I missing your question

//slideshow.jsexportconstplusSlides = (n)=>{
    showSlides(slideIndex += n);
}

and import it where you need to

//Homepage.js
import {plusSlides} from'./slideshow'

handleClick (event) {
        plusSlides(1); 
    }

Post a Comment for "Call Js Function From Another File In React?"