slorber / react-async-hook

React hook to handle any async operation in React components, and prevent race conditions
https://sebastienlorber.com/handling-api-request-race-conditions-in-react
1.19k stars 45 forks source link

Accept `undefined` on `onSuccess`/`onError` #86

Open fsmaia opened 2 years ago

fsmaia commented 2 years ago

When receiving onSuccess/onError parameters externally, it's very common to handle it as optional, as in the following example:

type Props = {
  onSuccess?: (data: ...) => void;
};

const Component: React.FC<Props> = ({ onSuccess }) => {
  const { ... } = useAsync(..., [...], { onSuccess });
};

In the current implementation, for this scenario, the default onSuccess (noop) will be replaced with undefined: https://github.com/slorber/react-async-hook/blob/master/src/index.ts#L128

Larisa00dila commented 2 years ago

Hey

pig800509 commented 1 year ago

my another answer