File tree Expand file tree Collapse file tree 3 files changed +19
-27
lines changed
eslint-plugin-react-hooks Expand file tree Collapse file tree 3 files changed +19
-27
lines changed Original file line number Diff line number Diff line change @@ -4446,19 +4446,15 @@ const tests = {
44464446 errors : [
44474447 `Effect callbacks are synchronous to prevent race conditions. ` +
44484448 `Put the async function inside:\n\n` +
4449- `useEffect(() => {\n` +
4450- ` let ignore = false;\n` +
4451- ` fetchSomething();\n` +
4452- `\n` +
4453- ` async function fetchSomething() {\n` +
4454- ` const result = await ...\n` +
4455- ` if (!ignore) setState(result);\n` +
4456- ` }\n` +
4457- `\n` +
4458- ` return () => { ignore = true; };\n` +
4459- `}, ...);\n` +
4460- `\n` +
4461- `This lets you handle multiple requests without bugs.` ,
4449+ 'useEffect(() => {\n' +
4450+ ' async function fetchData() {\n' +
4451+ ' // You can await here\n' +
4452+ ' const response = await MyAPI.getData(someId);\n' +
4453+ ' // ...\n' +
4454+ ' }\n' +
4455+ ' fetchData();\n' +
4456+ `}, [someId]); // Or [] if effect doesn't need props or state\n\n` +
4457+ 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching' ,
44624458 ] ,
44634459 } ,
44644460 {
Original file line number Diff line number Diff line change @@ -112,19 +112,15 @@ export default {
112112 message :
113113 `Effect callbacks are synchronous to prevent race conditions. ` +
114114 `Put the async function inside:\n\n` +
115- `useEffect(() => {\n` +
116- ` let ignore = false;\n` +
117- ` fetchSomething();\n` +
118- `\n` +
119- ` async function fetchSomething() {\n` +
120- ` const result = await ...\n` +
121- ` if (!ignore) setState(result);\n` +
122- ` }\n` +
123- `\n` +
124- ` return () => { ignore = true; };\n` +
125- `}, ...);\n` +
126- `\n` +
127- `This lets you handle multiple requests without bugs.` ,
115+ 'useEffect(() => {\n' +
116+ ' async function fetchData() {\n' +
117+ ' // You can await here\n' +
118+ ' const response = await MyAPI.getData(someId);\n' +
119+ ' // ...\n' +
120+ ' }\n' +
121+ ' fetchData();\n' +
122+ `}, [someId]); // Or [] if effect doesn't need props or state\n\n` +
123+ 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching' ,
128124 } ) ;
129125 }
130126
Original file line number Diff line number Diff line change @@ -358,7 +358,7 @@ function commitHookEffectList(
358358 ' // ...\n' +
359359 ' }\n' +
360360 ' fetchData();\n' +
361- ' }, [someId]);\n\n' +
361+ ` }, [someId]); // Or [] if effect doesn't need props or state \n\n` +
362362 'Learn more about data fetching with Hooks: https://fb.me/react-hooks-data-fetching' ;
363363 } else {
364364 addendum = ' You returned: ' + destroy ;
You can’t perform that action at this time.
0 commit comments