Answer the question
In order to leave comments, you need to log in
How to make it easier to write a function?
const f = (data) => {
return new Promise((resolve) => {
resolve({
data: data
});
}
Answer the question
In order to leave comments, you need to log in
Simplify by removing the meaningless promise.
There is nowhere easier:
const f = (data) => ({data});
Alexey Ukolov is right.
But if for some reason you need a promise (for a chain then
there, or something else), then there is a built-in helper for this:
You can also use it with the same success:
const f = data => Promise.resolve({data});
const f = async data => ({data});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question