Plaese I want to setTimeOut in my class base component. Trying different method but still it did not work. I want the setTimeout to call nextClick/onClickI after a specified second but, still don't understand how to go about it. Please help, if you have an idea. below is the component code...
class AbCarousel extends Component {
state = {
data: []
}
myRef = React.createRef();
getData = async () => {
const res = await fetch('aboutdata.json');
const data = await res.json();
this.setState({data: data})
}
componentDidMount() {
this.getData();
}
prevClick = () => {
const slide = this.myRef.current;
slide.scrollLeft -= slide.offsetWidth;
if (slide.scrollLeft <= -0){
slide.scrollLeft = slide.scrollWidth;
}
};
nextClick = () => {
const slide = this.myRef.current;
slide.scrollLeft += slide.offsetWidth;
if (slide.scrollLeft >= (slide.scrollWidth - slide.offsetWidth)) {
slide.scrollLeft = 0;
}
};
render() {
const { data } = this.state;
return (
<div className="wrapper">
<div className="app" ref={this.myRef}>
<AbCard data={data} />
</div>
<div className="row">
<div className="prev" onClick={this.prevClick}>
<div><FaChevronLeft /></div>
</div>
<div className="next" onClick={this.nextClick}>
<div><FaChevronRight /></div>
</div>
</div>
</div>
)
}
}
export default AbCarousel
setTimeoutin your code. Can you update your question to include the relevant code you are trying to usesetTimeoutin? What is the problem you are trying to solve with a timeout? When/where do you want a timeout?