Closed joebien closed 6 years ago
@joebien
When you wrap your own component with react-timeout
, your component is provided with the setTimeout
function in its props. So the this.props.setTimeout
function in your component is the react-timeout
function. Hope that's somewhat understandable! 😄
Hi, I'm getting this.props.setTimeout is not a function. I followed the instructions but I dont know what else to do anymore.
This is my code
import React from "react";
import ReactTimeout from 'react-timeout'
import "./main.css";
import Content from "../content/content";
import { connect } from "react-redux";
class Main extends React.Component {
constructor(props) {
super(props);
this.state = {
isHovered: false,
scrollValue: 0
};
this.smoothScroll = this.smoothScroll.bind(this);
}
smoothScroll = () => {
this.setState(prevState => {scrollValue: prevState+1})
}
componentDidMount = () => {
this.props.setTimeout( this.smoothScroll , 100) // call the `toggle` function after 100ms
}
}
@alphakennyn how are you calling the ReactTimeout
on the Main
component? I assume you're doing it in conjunction with the connect
somewhere later?
I'm calling it from componentDidMount()
. I'm trying to move from traditional javascript setTimeout to react-timeout. As of now, my connect
is just imported but not in use yet.
My error is called here
this.props.setTimeout
is not a function
@alphakennyn
If I had to guess I'd think you've forgotten to call the ReactTimeout
function on Main
.
There's an example of how to export it for a class in the readme (last line of the code example):
https://github.com/plougsgaard/react-timeout#es6-classes---the-light-switch
Oh you're right! thank you!
Glad it worked out. 😄
please help! How does
this.props.setTimeout
access the react-timeout function?