Skip to content

Instantly share code, notes, and snippets.

@dburles
Created October 25, 2020 22:54
  • Select an option

Select an option

Revisions

  1. dburles created this gist Oct 25, 2020.
    15 changes: 15 additions & 0 deletions createSuspendEvent.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // https://codesandbox.io/s/createsuspendevent-7yuzl?file=/src/Test.js
    const createSuspendEvent = (fn) => {
    return () => {
    createResource(() => {
    return new Promise((resolve) => {
    fn((cleanup) => {
    if (typeof cleanup === 'function') {
    cleanup();
    }
    resolve();
    });
    });
    })(fn);
    };
    };