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

To help you get started, we’ve selected a few react-use 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 kiwicom / the-zoo / frontend / packages / core-api / src / app / App.tsx View on Github external
function useConfigLoader(
  configLoader: AppConfigLoader | undefined,
  components: AppComponents,
  appThemeApi: AppThemeApi,
): { api: ConfigApi } | { node: JSX.Element } {
  // Keeping this synchronous when a config loader isn't set simplifies tests a lot
  const hasConfig = Boolean(configLoader);
  const config = useAsync(configLoader || (() => Promise.resolve([])));

  let noConfigNode = undefined;

  if (hasConfig && config.loading) {
    const { Progress } = components;
    noConfigNode = <progress>;
  } else if (config.error) {
    const { BootErrorPage } = components;
    noConfigNode = ;
  }

  // Before the config is loaded we can't use a router, so exit early
  if (noConfigNode) {
    return {
      node: (
        </progress>
github maxindelicato / makerads / src / components / leaderboard.js View on Github external
export default () =&gt; {
  const { error, loading, value } = useAsync(fetchLeaderboard);
  return (
    <div id="leaderboard">
      <h2>Top Referrers</h2>
      {/* <p>Get referrals from the biggest names in the community.</p> */}
      {value ? (
        
            {value.map(ref =&gt; (
              <table>
          <thead>
            <tr>
              <th>
              </th><th>Impressions</th>
              <th>Clicks</th>
            </tr>
          </thead>
          <tbody><tr></tr></tbody></table></div>
github sillsdev / appbuilder-portal / source / SIL.AppBuilder.Portal.Frontend / src / data / async-waiter.tsx View on Github external
export function AsyncWaiter({
  children,
  fn,
  loadingProps = {},
  sizeClass,
}: {
  children?: any;
  fn: Fn;
  loadingProps?: any;
  sizeClass?: string;
}) {
  if (!fn) {
    throw new Error(`Function passed to AsyncWaiter must not be falsey`);
  }

  const state = useAsync(fn as any);
  const { error, loading, value } = state;

  if (error) {
    throw error;
  }

  if (loading) {
    return (
      <div>
        
      </div>
    );
  }

  return children({ value });
}
github vietnam-devs / coolstore-microservices / src / web / back-office / src / App.tsx View on Github external
export default () =&gt; {
  const state: any = useAsync(getUser)
  return (
    <div>
      
        
        
            !state.loading &amp;&amp; state.value != null &amp;&amp; state.value.access_token != null ? (
              
            ) : (
              
            )</div>
github raviqqe / tasks / src / infrastructure / react / App.tsx View on Github external
archiveProject,
    authenticationStore: { signedIn },
    createProject,
    deleteProject,
    projectsStore: { archivedProjects, currentProject, projects },
    tasksStore: { doneTasks, todoTasks },
    initialize,
    repositoryURL,
    signIn,
    signOut,
    switchCurrentProject,
    unarchiveProject,
    updateProject,
    ...props
  }: IProps) =&gt; {
    useAsync(initialize, []);
    const [projectsShown, setProjectsShown] = useState(false);

    return signedIn &amp;&amp; !projectsShown ? (
       setProjectsShown(true)}
        signOut={signOut}
        todoTasks={todoTasks}
      /&gt;
    ) : signedIn ? (
github avkonst / hookstate / examples / src / App.tsx View on Github external
const SourceCodeView = (props: { url: string }) =&gt; {
    const code = useAsync(() =&gt; new Promise((resolve, reject) =&gt; {
        request.get(
            props.url,
            (err, resp, body) =&gt; err ? reject(err) : resolve(body));
        }
    ))

    let codeString = ''
    if (code.loading) {
        codeString = `Loading code sample from: ${props.url}`;
    } else if (code.error) {
        codeString = `Failure to load code sample from: ${props.url} (${code.error.toString()})`;
    } else {
        codeString = code.value ? code.value.toString() : `Failure to load code sample from: ${props.url}`;
    }

    return (