Workiva / over_react

A library for building statically-typed React UI components using Dart.
Other
428 stars 58 forks source link

How can we use timeout function inside overreact component ? #184

Closed arun-sahadevan closed 6 years ago

arun-sahadevan commented 6 years ago
  • Issue Type: Question
  • over_react Version(s): 1.24.1

How can we use time out function inside overreact on load of a component?

Tried javascript and jquery functions . But they were not compatible with Overeact . Can you please give a sample where an action is performed on page load with a timeout ?

FYI: @greglittlefield-wf @aaronlademann-wf @kealjones-wk @evanweible-wf @maxwellpeterson-w

aaronlademann-wf commented 6 years ago

@arun-sahadevan I would recommend using the Future.delayed constructor.

import 'dart:async';
import 'package:over_react/over_react.dart';

@Factory()
UiFactory<WidgetProps> Widget;

@Props()
class WidgetProps extends UiProps {}

@Component()
class WidgetComponent extends UiComponent<WidgetProps> {
  @override
  void componentDidMount() {
    new Future.delayed(const Duration(/* whatever duration you want to wait */)).then((_) {
      // Do something once the delay is over
    });
  }

  @override
  render() {
    // ...
  }
}