Skip to content

Create useAsyncValue hook #233

@leroykorterink

Description

@leroykorterink
import { useBeforeMount } from '@mediamonks/react-hooks';
import { useState } from 'react';

export function useAsyncValue<T extends () => any>(initializeFunction: T): Awaited<ReturnType<T>> | undefined {
  const [value, setValue] = useState<Awaited<ReturnType<T>> | undefined>();

  useBeforeMount(async () => {
    setValue(await initializeFunction());
  });

  return value;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions