react-async-hook icon indicating copy to clipboard operation
react-async-hook copied to clipboard

Accept `undefined` on `onSuccess`/`onError`

Open fsmaia opened this issue 3 years ago • 2 comments

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

fsmaia avatar Jul 25 '22 23:07 fsmaia

Hey

Larisa00dila avatar Nov 01 '22 01:11 Larisa00dila