Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create useAsyncValue hook #233

Open
leroykorterink opened this issue Sep 7, 2023 · 2 comments
Open

Create useAsyncValue hook #233

leroykorterink opened this issue Sep 7, 2023 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@leroykorterink
Copy link
Collaborator

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;
}
@leroykorterink leroykorterink added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Sep 7, 2023
@Franqsanz
Copy link

Hello, is it copying that same example and saving it in a folder with the same name?

@ThaNarie
Copy link
Member

ThaNarie commented Sep 9, 2023

@Franqsanz There are a few more steps to it (docs, tests, etc).
You can check the readme to see what's needed to contribute a new hook to the repo:
https://github.com/mediamonks/react-hooks#development

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants