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

To help you get started, we’ve selected a few react-async 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 async-library / react-async / examples / with-typescript / src / App.tsx View on Github external
const UseAsync = () => {
  const state = useAsync({ promiseFn: loadFirstName, userId: 1 })
  return (
    <>
      Loading...
      {error => `Something went wrong: ${error.message}`}
      
        {data => (
          <div>
            <strong>Loaded some data:</strong>
            <pre>{JSON.stringify(data, null, 2)}</pre>
          </div>
        )}
      
    
  )
}
github bestofjs / bestofjs-webui / src / api / hooks.js View on Github external
export function useFetchProjectReadMe({ full_name, branch }) {
  return useAsync({
    promiseFn: fetchProjectReadMe,
    watch: full_name,
    full_name,
    branch
  })
}
github GiraffeTools / GiraffeTools / frontend / giraffe / components / profileBox.js View on Github external
const ProfileBox = ({username, activeProjects}) =&gt; {
  const {data, error, isLoading} = useAsync(loadUser, {username});
  const user = isLoading
    ? 'Loading...'
    : error
      ? 'User not found'
      : data.userName;
  const avatarUrl =
    isLoading || error ? '/static/img/giraffetools_logo.png' : data.avatar_url;
  const loggedIn = isLoading || error ? false : data.loggedIn;
  return (
    <div>
      <div style="{styles.sticky}">
        <div style="{styles.box}">
          <img style="{styles.profilePic}" src="{avatarUrl}">
          <h3 style="{styles.username}">{user}</h3>
          </div></div></div>
github 3scale / porta / portafly / src / components / pages / accounts / listing / AccountsListingPage.tsx View on Github external
const AccountsListingPage: React.FunctionComponent = () =&gt; {
  const { data: accounts, error, isPending } = useAsync(getDeveloperAccounts)
  const { t } = useTranslation('audienceAccountsListing')
  useDocumentTitle(t('title_page'))

  return (
    &lt;&gt;
      
        
          
            
              
            
          
          
            <button>}</button>
github async-library / react-async / packages / react-async-devtools / src / index.spec.js View on Github external
const Async = props => {
  const { data, error, isPending } = useAsync(props)
  if (isPending) return "loading"
  if (error) return error
  if (data) return data
  return null
}
github 3scale / porta / portafly / src / components / pages / accounts / AccountsIndexPage.tsx View on Github external
const AccountsIndexPage: React.FunctionComponent = () =&gt; {
  const { data: accounts, error, isPending } = useAsync(getDeveloperAccounts)
  const { t } = useTranslation('accountsIndex')
  useDocumentTitle(t('title_page'))

  return (
    &lt;&gt;
github StoDevX / AAO-React-Native / source / views / directory / list.js View on Github external
export function DirectoryView(props: Props) {
	let [typedQuery, setTypedQuery] = React.useState('')
	let searchQuery = useDebounce(typedQuery, 500)

	let {data, error, isLoading}: ReactAsyncResult = useAsync(
		searchDirectory,
		{query: searchQuery, watch: searchQuery},
	)

	let results = data ? data.results : []

	let renderRow = ({item}: {item: DirectoryItem}) =&gt; (
		 {
				props.navigation.navigate('DirectoryDetailView', {contact: item})
			}}
		/&gt;
	)

	return (
github 3scale / porta / portafly / src / components / pages / applications / ApplicationsIndexPage.tsx View on Github external
const ApplicationsIndexPage: React.FunctionComponent = () =&gt; {
  const { authToken } = useAuth()
  const { t } = useTranslation('applicationsIndex')
  useDocumentTitle(t('page_title'))
  const { data: applications, isPending, error } = useAsync(getApplications, { authToken })

  return (
    &lt;&gt;
github codexstanford / techlist-frontend-web / src / store / auth-context.js View on Github external
function AuthProvider(props) {
  const { client } = props;

  const [firstAttemptFinished, setFirstAttemptFinished] = React.useState(false);
  const {
    data = { user: null, listItems: [] },
    error,
    isRejected,
    isPending,
    isSettled,
    reload,
  } = useAsync({
    promiseFn: bootstrapAppData,
    client,
  });

  React.useLayoutEffect(() =&gt; {
    if (isSettled) {
      setFirstAttemptFinished(true);
    }
  }, [isSettled]);

  if (!firstAttemptFinished) {
    if (isPending) {
      return ;
    }
    if (isRejected) {
      return (
github bestofjs / bestofjs-webui / src / api / hooks.js View on Github external
export function useFetchProjectDetails({ full_name }) {
  return useAsync({
    promiseFn: fetchProjectDetails,
    watch: full_name,
    full_name
  })
}