0

IN ReactNative I have created one loader and this loader show and hide using by function. But when I am trying to call this function in setTimeout this is not working it returns me error like this -> this.showLoader is not a function. is undefined. But when I am tried to without setTimeout it working fine.

export default class ThirdScreen extends Component<Props> {

  constructor(props) {
        super(props)

    this.state = 
    {
       isLoading: false
    }
    this.showLoader = this.showLoader.bind(this);
  }

  componentDidMount() {

    setTimeout(function(){
      this.showLoader()
    }, 1000);
     //this.showLoader()
    }

    showLoader () {
      this.setState({ isLoading: true });
    }

    hideLoader = () => {
      this.setState({ isLoading: false });
    }
}

2 Answers 2

2

Hopefully, this will solve your problem

setTimeout(()=> this.showLoader(), 1000)
Sign up to request clarification or add additional context in comments.

Comments

0

Looks like showLoader() function is declared inside componentDidMount() so it's not accessible via this pointer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.