36 (node) => {
37 if (commentsReqInfo.isLoading) return
38 if (observer.current) observer.current.disconnect()
39 observer.current = new IntersectionObserver(async (entries) => { 40 if (entries[0].isIntersecting && hasMore) { 41 await getComments({ 42 postId: parseInt(postId as string), 43 lastId: lastId, 44 }) 45 } 46 }) 47 if (node) observer.current.observe(node)
48 },
49 [commentsReqInfo.isLoading, hasMore]
Using promises is forbidden in places where the TypeScript compiler allows them but they are not handled properly. These situations can often arise due to a missing await keyword or just a misunderstanding of the way async functions are handled/awaited.
const promise = Promise.resolve('value');
if (promise) {
// Do something
}
const val = promise ? 123 : 456;
while (promise) {
// Do something
}
const promise = Promise.resolve('value');
if (await promise) {
// Do something
}
const val = (await promise) ? 123 : 456;
while (await promise) {
// Do something
}
for (const value of [1, 2, 3]) {
await doSomething(value);
}
new Promise((resolve, reject) => {
// Do something
resolve();
});
const eventEmitter = new EventEmitter();
eventEmitter.on('some-event', () => {
doSomething();
});