0.1.5 • Published 5 years ago

@aicacia/async_component-react v0.1.5

Weekly downloads
7
License
(MIT OR Apache-2....
Repository
gitlab
Last release
5 years ago

ts-async_component-react

license docs npm (scoped) pipelines

aicacia async component for react

Async Component

import { Async } from "@aicacia/async_component-react";

<Async
  promise={Promise.resolve("Hello, world!")}
  onSuccess={(value) => value} // displays promise result "Hello, world!"
  onPending={() => "Loading..."}
  onError={(error) => error.message} // on error so message
/>;

useAsync hook

import { useAsync } from "@aicacia/async_component-react";

function AsyncHook() {
  const result = useAsync(Promise.resolve("Hello, world!"));

  return (
    <div>
      {result
        .map((result) => {
          if (result.isOk()) {
            return result.unwrap();
          } else {
            return result.unwrapErr().message;
          }
        })
        .unwrapOr("Loading...")}
    </div>
  );
}
0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago