我正在尝试redux
用作本地存储,我正在尝试添加地板,如您gif
在到那个平面列表,我的楼层正在渲染我添加的最近楼层消失,当我回到那个平面列表屏幕上再次返回时,它会自动呈现最近消失的楼层。请帮助我找出问题所在
这是我的代码
在redux中将新楼层添加到现有数组
const handleNewFloor = () => {
if (floorName === '') {
Snackbar.show({
text: 'Kindly Enter Floor Name',
});
} else {
let id = uuid.v1();
let localList = floorList;
const params = {
flo_id: id,
buil_id: item && item.buil_id,
hos_id: hos_id,
user_id: user && user.user_id,
flo_name: floorName,
hos_name: name,
buil_name: item && item.buil_name,
is_delete: '0',
mode: '0',
updated_date_time: new Date().toLocaleString(),
added_date_time: new Date().toLocaleString(),
userName: user && user.first_name + ' ' + user.last_name,
user_id: user && user.user_id,
};
let allFloor = [...floorList, params];
new Promise((rsl, rej) => {
addFloor(allFloor, rsl, rej);
})
.then((res) => {
Snackbar.show({
text: res,
});
// navigation.navigate('Home');
setUpdate(true);
floorRef.current.close();
setFloorName('');
console.log(res);
})
.catch((err) => {
Snackbar.show({
text: err,
});
console.log(err);
});
}
};
这是平面列表代码
<FlatList
showsVerticalScrollIndicator={false}
data={floors}
extraData={floors}
renderItem={renderFloor}
keyExtractor={(item) => item}
/>
const renderFloor = ({item, index}) => {
return (
<TouchableOpacity
onPress={() => {
navigation.navigate('Monitoring', {name, building, item});
}}
style={{
backgroundColor: index % 2 === 0 ? '#F7FEFF' : '#F2F6F9',
// margin: 0.2,
paddingHorizontal: 2,
paddingVertical: 15,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
// borderRadius: 4,
}}>
<View style={{flexDirection: 'row'}}>
<MaterialCommunityIcons
name="ruler"
color={'lightgray'}
size={25}
style={{alignSelf: 'center'}}
/>
<Text style={[styles.mediumText, {marginLeft: 10}]}>
{item.flo_name}
</Text>
</View>
<View style={{flexDirection: 'row'}}>
<Entypo name="chevron-small-right" color={'gray'} size={20} />
</View>
</TouchableOpacity>
);
};