How to use the react-async-hook.useAsync function in react-async-hook

To help you get started, we’ve selected a few react-async-hook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github celo-org / celo-monorepo / packages / mobile / src / fees / CalculateFee.tsx View on Github external
function useAsyncShowError(
  asyncFunction: ((...args: Args) => Promise) | (() => Promise),
  params: Args,
  showErrorFunction: typeof showError
): UseAsyncReturn {
  const asyncResult = useAsync(asyncFunction, params)

  useEffect(
    () => {
      // Generic error banner
      if (asyncResult.error) {
        showErrorFunction(ErrorMessages.CALCULATE_FEE_FAILED)
      }
    },
    [asyncResult.error]
  )

  return asyncResult
}
github xcarpentier / react-native-country-picker-modal / src / Flag.tsx View on Github external
const ImageFlag = memo(({ countryCode, flagSize }: FlagType) => {
  const { getImageFlagAsync } = useContext()
  const asyncResult = useAsync(getImageFlagAsync, [countryCode])
  if (asyncResult.loading) {
    return 
  }
  return (
    <img style="{[">
  )
})
github slorber / react-async-hook / example / index.tsx View on Github external
const StarwarsHeroLoaderBasic = ({ id }: { id: string }) =&gt; {
  const asyncHero = useAsync(fetchStarwarsHero, [id]);
  return ;
};
github jamaljsr / polar / src / components / designer / lightning / LightningNodeDetails.tsx View on Github external
const LightningDetails: React.FC = ({ node }) =&gt; {
  const { l } = usePrefixedTranslation('cmps.designer.lightning.LightningNodeDetails');
  const [activeTab, setActiveTab] = useState('info');
  const { getInfo, getBalances } = useStoreActions(s =&gt; s.lightning);

  const getInfoAsync = useAsync(
    async (node: LightningNode) =&gt; {
      if (node.status === Status.Started) {
        await getInfo(node);
        await getBalances(node);
      }
    },
    [node],
  );

  let extra: ReactNode | undefined;
  const { nodes } = useStoreState(s =&gt; s.lightning);
  const nodeState = nodes[node.name];
  if (node.status === Status.Started &amp;&amp; nodeState) {
    if (nodeState.balances) {
      const { confirmed } = nodeState.balances;
      extra = <strong>{abbreviate(confirmed)} sats</strong>;
github slorber / react-async-hook / example / index.tsx View on Github external
const StarwarsHeroLoaderDebounced = ({ id }: { id: string }) =&gt; {
  const debouncedFetchStarwarsHero = useConstant(() =&gt;
    AwesomeDebouncePromise(fetchStarwarsHero, 1000)
  );
  const asyncHero = useAsync(debouncedFetchStarwarsHero, [id]);
  return ;
};
github jamaljsr / polar / src / components / designer / bitcoind / BitcoindDetails.tsx View on Github external
const BitcoindDetails: React.FC&lt;{ node: BitcoinNode }&gt; = ({ node }) =&gt; {
  const { l } = usePrefixedTranslation('cmps.designer.bitcoind.BitcoinDetails');
  const [activeTab, setActiveTab] = useState('info');
  const { getInfo } = useStoreActions(s =&gt; s.bitcoind);
  const { nodes } = useStoreState(s =&gt; s.bitcoind);
  const getInfoAsync = useAsync(
    async (node: BitcoinNode) =&gt; {
      if (node.status === Status.Started) {
        await getInfo(node);
      }
    },
    [node],
  );

  let extra: ReactNode | undefined;
  const nodeState = nodes[node.name];
  if (node.status === Status.Started &amp;&amp; nodeState &amp;&amp; nodeState.walletInfo) {
    extra = <strong>{nodeState.walletInfo.balance} BTC</strong>;
  }

  const tabHeaders = [
    { key: 'info', tab: l('info') },
github xcarpentier / react-native-country-picker-modal / src / Flag.tsx View on Github external
const EmojiFlag = memo(({ countryCode, flagSize }: FlagType) =&gt; {
  const { getEmojiFlagAsync } = useContext()
  const asyncResult = useAsync(getEmojiFlagAsync, [countryCode])

  if (asyncResult.loading) {
    return 
  }
  return (
    
  )
})

react-async-hook

Async hook

MIT
Latest version published 3 years ago

Package Health Score

53 / 100
Full package analysis