I'm working with Reactjs and I need to show a message using a setTimeout but it always returns a number to me. Does anyone know the reason?
This is my code:
messageError = () => {
return <h1>Error!</h1>
}
render() {
return (
...
{ this.props.error.code != undefined ?
setTimeout(() => { this.messageError() }, 3000) : null }
Thanks!
setTimeoutdoes not return anything like you think here. It returns a positive integer and executes something. Here you are invoking your function but its return value can't be rendered like that. What is your intention here? Why do you want a delay?setTimeoutlike that.