Sign in
Log inSign up

Tried sth but it's not working...

DK's photo
DK
·Nov 28, 2017

Hey. I've tried to create what you said. But I get an error. How can I call timer() inside componentDidMount? This whole code might be wrong. So I would be glad if you could help. :)

export default class About extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      arr: this.props.language.about.style[0]
    };
  }

  timer() {
    let i = 0;
    function createTimer() {
      this.setState({
        arr: this.props.language.about.style[i]
      });
      i++;
      if (i === this.props.language.about.style.length) {
        i = 0;
      }
    }
    setInterval(createTimer, 500);
  }

  componentDidMount() {
    timer();
  }

  render() {
    return (
      <div>{this.state.arr}</div>
    );
  }
}
Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct