Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0de5c05

Browse files
committed
solution: useApi custom hook
1 parent3804516 commit0de5c05

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

‎src/components/Feed/index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,29 @@ import "./styles.css";
66
importfetchDatafrom"../../services/api";
77

88
exportconstuseApi=url=>{
9-
// TODO: loading, error, data loader from API
10-
// TODO: pass the url in so that we call fetchData(url)
11-
return{
12-
loading,
13-
error,
14-
data
15-
};
16-
};
17-
18-
exportconstFeed=()=>{
199
const[loading,setLoading]=React.useState(true);
2010
const[error,setError]=React.useState(null);
2111
const[data,setData]=React.useState(null);
2212

2313
React.useEffect(()=>{
24-
fetchData("messages")
14+
fetchData(url)
2515
.then(result=>{
2616
setData(result);
2717
setLoading(false);
2818
})
2919
.catch(error=>{
3020
setError(error);
3121
});
32-
},[]);
22+
},[url]);
23+
return{
24+
loading,
25+
error,
26+
data
27+
};
28+
};
3329

30+
exportconstFeed=()=>{
31+
const{ loading, error, data}=useApi("messages");
3432
if(loading){
3533
return(
3634
<divclassName="Feed">

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp