141
rated 0 times
[
147]
[
6]
/ answers: 1 / hits: 104386
/ 7 Years ago, thu, april 6, 2017, 12:00:00
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 have this function that increases the current slide index, like so:
function plusSlides(n) {
showSlides(slideIndex += n);
}
In Homepage.jsx
, I have a next button that should call plusSlides
from slideshow.js
when it is clicked, like so:
class NextButton extends React.Component {
constructor() {
super();
this.onClick = this.handleClick.bind(this);
}
handleClick (event) {
script.plusSlides(1); // I don't know how to do this properly...
}
render() {
return (
<a className=next onClick={this.onClick}>
❯
</a>
);
}
}
More From » reactjs