Skip to content

Commit 790b5f2

Browse files
committed
Fix: crash when change order home
1 parent acf56dc commit 790b5f2

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

app/components/lists/HorizontalLBStat.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
import React from 'react';
2-
import { Text, View, StyleSheet } from 'react-native';
1+
import React from 'react'
2+
import { Text, View, StyleSheet } from 'react-native'
33

4-
import { ThemeContext } from '~/contexts/theme';
5-
import size from '~/styles/size';
4+
import { ThemeContext } from '~/contexts/theme'
5+
import size from '~/styles/size'
66

77
const HorizontalLBStat = ({ stats }) => {
88
const theme = React.useContext(ThemeContext)
99
const [maxCount, setMaxCount] = React.useState(0)
1010

1111
React.useEffect(() => {
1212
if (typeof stats === 'string') return
13-
let maxCount = 1;
13+
if (!stats || !stats.length) return
14+
let maxCount = 1
1415
stats?.forEach((stat) => {
1516
if (stat.listen_count > maxCount) maxCount = stat.listen_count
1617
})
@@ -25,6 +26,8 @@ const HorizontalLBStat = ({ stats }) => {
2526
marginVertical: 50
2627
}}>{stats}</Text>
2728
)
29+
30+
if (!stats || !stats.length) return (null)
2831
return (
2932
<View style={styles.scrollContainer(stats?.length)}>
3033
{
@@ -72,4 +75,4 @@ const styles = StyleSheet.create({
7275
}),
7376
})
7477

75-
export default HorizontalLBStat;
78+
export default HorizontalLBStat

app/components/lists/HorizontalList.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,18 @@ const HorizontalList = ({ refresh, id, enable }) => {
3636
if (config.query) {
3737
getList()
3838
}
39-
}, [config, refresh, enable])
39+
return () => {
40+
setList(null)
41+
}
42+
}, [config, enable, id])
43+
44+
React.useEffect(() => {
45+
if (!enable) return
46+
if (!refresh) return
47+
if (config.query) {
48+
getList()
49+
}
50+
}, [refresh])
4051

4152
React.useEffect(() => {
4253
if (!enable) return

0 commit comments

Comments
 (0)