virtualdom.usesignal.tsx 655 B

1234567891011121314151617181920212223242526
  1. import * as React from 'react';
  2. import { ReactWidget, UseSignal } from '@jupyterlab/apputils';
  3. import { ISignal, Signal } from '@lumino/signaling';
  4. import { Widget } from '@lumino/widgets';
  5. function MyComponent() {
  6. return <div>My Widget</div>;
  7. }
  8. function UseSignalComponent(props: { signal: ISignal<MyWidget, void> }) {
  9. return <UseSignal signal={props.signal}>{() => <MyComponent />}</UseSignal>;
  10. }
  11. class MyWidget extends ReactWidget {
  12. render() {
  13. return <UseSignalComponent signal={this._signal} />;
  14. }
  15. private _signal = new Signal<this, void>(this);
  16. }
  17. const myWidget: Widget = new MyWidget();
  18. Widget.attach(myWidget, document.body);