@@ -346,22 +346,23 @@ function commitHookEffectList(
346
346
} else if ( typeof destroy . then === 'function' ) {
347
347
addendum =
348
348
'\n\nIt looks like you wrote useEffect(async () => ...) or returned a Promise. ' +
349
- 'Instead, you may write an async function separately ' +
350
- 'and then call it from inside the effect:\n\n' +
351
- 'async function fetchComment(commentId) {\n' +
352
- ' // You can await here\n' +
353
- '}\n\n' +
349
+ 'Instead, write the async function inside your effect ' +
350
+ 'and call it immediately:\n\n' +
354
351
'useEffect(() => {\n' +
355
- ' fetchComment(commentId);\n' +
356
- '}, [commentId]);\n\n' +
357
- 'In the future, React will provide a more idiomatic solution for data fetching ' +
358
- "that doesn't involve writing effects manually." ;
352
+ ' async function fetchData() {\n' +
353
+ ' // You can await here\n' +
354
+ ' const response = await MyAPI.getData(someId);\n' +
355
+ ' // ...\n' +
356
+ ' }\n' +
357
+ ' fetchData();\n' +
358
+ '}, [someId]);\n\n' +
359
+ 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching' ;
359
360
} else {
360
361
addendum = ' You returned: ' + destroy ;
361
362
}
362
363
warningWithoutStack (
363
364
false ,
364
- 'An Effect function must not return anything besides a function, ' +
365
+ 'An effect function must not return anything besides a function, ' +
365
366
'which is used for clean-up.%s%s' ,
366
367
addendum ,
367
368
getStackByFiberInDevAndProd ( finishedWork ) ,
0 commit comments