@aicacia/async_component-react
v0.1.5
Published
aicacia async component for react
Downloads
10
Readme
ts-async_component-react
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>
);
}