当我尝试在我的 React 本机应用程序中使用 Toast 消息时,从一个页面导航到另一页面时,我确实知道在哪种情况下会出现此错误,但是应用程序突然崩溃,没有任何错误。当我尝试调试时,它显示“无法读取(读取显示吐司)中未定义的属性”
// Importing the Toast
import { Button, Grid, Col, Text, Toast, Root } from 'native-base';
// Declaring the Toast
const toastr = {
showToast: (message, duration = 2500,) => {
Toast.show({
text: message,
duration,
position: 'bottom',
textStyle: { textAlign: 'center', fontSize: moderatescale(12), fontWeight: 'bold' },
style: { backgroundColor: 'black', borderRadius: moderatescale(40), marginRight: moderatescale(20), marginLeft: moderatescale(20), marginBottom: moderatescale(55) }
});
},
};
// Calling the Toast like this one !!!
let message = "No Workorders found for this Asset"
toastr.showToast(message);
我需要有关上述问题的帮助来解决或任何其他解决方案来防止它!!!`
使用原生库中的 useToast。
从'native-base'导入{useToast};
const toast = useToast();
吐司.show({ 标题:《世界你好》 })