File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,43 @@ new MyRuleTester().run("/syntax", {
125125 }
126126 ` ,
127127 } ,
128+ {
129+ // https://github.com/NickvanDyke/eslint-plugin-react-you-might-not-need-an-effect/issues/16
130+ name : "Async derived setter" ,
131+ todo : true ,
132+ code : js `
133+ import { useEffect, useState } from 'react';
134+
135+ export const App = () => {
136+ const [response, setResponse] = useState(null);
137+
138+ const fetchYesNoApi = () => {
139+ return (async () => {
140+ try {
141+ const response = await fetch('https://yesno.wtf/api');
142+ if (!response.ok) {
143+ throw new Error('Network error');
144+ }
145+ const data = await response.json();
146+ setResponse(data);
147+ } catch (err) {
148+ console.error(err);
149+ }
150+ })();
151+ };
152+
153+ useEffect(() => {
154+ (async () => {
155+ await fetchYesNoApi();
156+ })();
157+ }, []);
158+
159+ return (
160+ <div>{response}</div>
161+ );
162+ };
163+ `
164+ }
128165 ] ,
129166 invalid : [
130167 {
You can’t perform that action at this time.
0 commit comments