Answer the question
In order to leave comments, you need to log in
What is the return type of the function that returns useCallback?
Given the function below, what type does it return? Thanks in advance.
const useSendMessage = (): ??? => {
const dispatch = useDispatch();
return useCallback(
(id: number, message: Message) => {
dispatch(Operation.sendMessage(id, message));
},
[dispatch]
);
};
Answer the question
In order to leave comments, you need to log in
So, just look at what useCallback returns.
Or don't write anything. TS will infer the return type itself
https://github.com/DefinitelyTyped/DefinitelyTyped...
Accordingly, the type will be:
(id: number, message: Message) => void
const useSendMessage = (): (id: number, message: Message) => void => {
const dispatch = useDispatch();
return useCallback(
(id: number, message: Message) => {
dispatch(Operation.sendMessage(id, message));
},
[dispatch]
);
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question