Skip to content

Commit 1fd19db

Browse files
committed
feat: 测试一下useFetchData这个hooks编写是否成功
1 parent 8b220ad commit 1fd19db

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

src/hooks/useFetchData/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ function useFetchData<T = any>(url: string, options?: IRequestOptions): IFetchRe
4040
request(url, options || {}, abortControllerRef.current)
4141
.then((res) => {
4242
const { code, message, data } = res as IResponseData;
43-
if (code !== 0) {
43+
// 这里后期做处理,判断返回的code,不同code做不同的提示就行
44+
if (code !== 10000) {
4445
console.log('Error Msg: ', message);
4546
throw new Error(message);
4647
}
@@ -53,7 +54,7 @@ function useFetchData<T = any>(url: string, options?: IRequestOptions): IFetchRe
5354
setLoading(false);
5455
});
5556
return () => destory();
56-
}, [url, options]);
57+
}, [url, JSON.stringify(options)]);
5758

5859
return { loading, data: result, error };
5960
}

src/screens/Auth/Sign/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @FilePath: \SunOfBeacheRN\src\screens\Auth\Sign\index.tsx
77
* @Description:登录页面
88
*/
9-
import React, { useState } from 'react';
9+
import React, { useEffect, useState } from 'react';
1010
import {
1111
Text,
1212
Input,
@@ -20,6 +20,7 @@ import {
2020
} from 'native-base';
2121
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
2222
import AntDesign from 'react-native-vector-icons/AntDesign';
23+
import useFetchData from '@src/hooks/useFetchData';
2324
const Sign = (props: any) => {
2425
const { setSwitchFormStatus, setSwitchFormTitle } = props;
2526
const handleClickRegister = () => {
@@ -32,6 +33,7 @@ const Sign = (props: any) => {
3233
};
3334
const [show, setShow] = useState(false);
3435
const handleClick = () => setShow(!show);
36+
3537
return (
3638
<>
3739
<VStack space={3} px="8" alignItems="center" w="100%">

src/screens/Auth/SignHeader/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
import React from 'react';
1010
import { Center, Image } from 'native-base';
1111

12-
const SignHeader = () => {
12+
const SignHeader = (props: any) => {
13+
const { data } = props;
1314
return (
1415
<Center mb="6">
1516
<Image
1617
size={100}
1718
alt="fallback text"
1819
borderRadius={100}
1920
source={{
20-
uri: 'https://www.w3schools.com/css/img_lights.jpg',
21+
uri: data,
2122
}}
2223
fallbackSource={{
23-
uri: 'https://www.w3schools.com/css/img_lights.jpg',
24+
uri: data,
2425
}}
2526
/>
2627
</Center>

src/screens/Auth/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import SignHeader from './SignHeader';
1313
import Sign from './Sign';
1414
import ForgetPassword from './ForgetPassword';
1515
import Register from './Register';
16+
import useFetchData from '@src/hooks/useFetchData';
1617

1718
const Auth = () => {
1819
// 切换不同的表单
@@ -40,10 +41,15 @@ const Auth = () => {
4041
);
4142
}
4243
};
44+
// TODO:明天完成fetch的后期编写和登录逻辑的编写
45+
// 获取头像
46+
const { data, loading } = useFetchData('https://api.sunofbeaches.com/uc/user/avatar/13132053657');
47+
console.log('data', data);
48+
console.log('loading', loading);
4349
return (
4450
<>
4551
<Box style={styles.container}>
46-
<SignHeader />
52+
<SignHeader data={data} />
4753
<Heading>{switchFormTitle}</Heading>
4854
{handleSwitchFormStatus()}
4955
</Box>

0 commit comments

Comments
 (0)