How to use the react-async.useFetch 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 3scale / porta / portafly / src / pages / Applications.tsx View on Github external
const Applications: React.FunctionComponent = () => {
  const { t } = useTranslation('applications')
  useDocumentTitle(t('listing.page_title'))

  const columns = [
    'Name',
    'State',
    'Account',
    'Plan',
    'Created at'
  ]
  let rows

  const { data, isPending } = useFetch(
    '/applications',
    { headers: { Accept: 'application/json' } }
  )

  if (!isPending && data) {
    const applications = data.applications.application // TODO: Check the server side xml2json
    const applicationsArray = Array.isArray(applications) ? applications : [{ ...applications }]

    rows = applicationsArray.map(
      (app: any) => ({
        cells: [
          app.name,
          app.state,
          'Developer',
          app.plan.name,
          app.created_at