1.0.1 • Published 2 years ago

@ricokahler/promise-suspender v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

@ricokahler/promise-suspender

This is an experimental package that plays around with the idea of using suspense for promises.

import { Suspense } from 'react';
import { createPromiseSuspender } from '@ricokahler/promise-suspender';
import { somethingAsync } from '../';

const usePromise = createPromiseSuspender();

function MySuspendingComponent({ foo }) {
  const value = usePromise(async () => {
    const { data } = await somethingAsync(foo, bar);
    return data;
  }, [foo, bar]); // 👈 Note: these have to be strings

  return <>{value}</>;
}

function Parent() {
  return (
    <Suspense fallback={<>Loading...</>}>
      <MySuspendingComponent />
    </Suspense>
  );
}
1.0.1

2 years ago

1.0.0

2 years ago