Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timers #27

Open
streamich opened this issue Feb 13, 2018 · 1 comment
Open

Timers #27

streamich opened this issue Feb 13, 2018 · 1 comment

Comments

@streamich
Copy link
Contributor

Create <Timer> or <Reminder> components

@streamich
Copy link
Contributor Author

streamich commented Feb 13, 2018

class Timer extends Component {
  static propTypes = {
    children: Types.func.isRequired,
    ...timerProps
  };

  static defaultProps = {
    onTime: noop
  };

  state = {
    timed: false
  };

  componentDidMount () {
    this.timeout = setTimeout(() => {
      this.props.onTime();
      this.setState({timed: true});
    }, this.props.time);
  }

  componentWillUnmount () {
    clearTimeout(this.timeout);
  }

  render () {
    if (process.env.NODE_ENV !== 'production') {
      if (typeof this.props.children !== 'function') {
        throw new TypeError('Children in <Timer/> must be a function.');
      }
    }

    return this.props.children(this.state.timed);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant