1.1.1 • Published 3 years ago

@alifaishol/use-async v1.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
3 years ago

React Hook for Managing Async State

npm

Usage

const options = {
  initialData: undefined,
  onError: (error: Error) => undefined,
  onSuccess: (data: Profile) => undefined,
  initialLoadingState: false,
}

const {
  exec,
  setData,
  state: {loading, data, error},
} = useAsync(Api.profile.getProfile, options);

useEffect(() => {
  exec('params for the original function (getProfile)');
}, [exec]);

const logout = useCallback((): void => {
  setData(undefined);
}, [setData]);