如何修复nativebase toast错误undefined不是一个对象(评估'this.toastInstance._root')

问题描述 投票:0回答:2

我在react-native项目中使用nativebase("native-base": "^2.12.1")。我将对反应组件类中的方法使用show toast

assignTicket(id) {
    return Toast.show({
        text: "Wrong password!",
        buttonText: "Okay",
        duration: 3000,
        type: "success"
    });   
}

但是我在调​​用此方法时遇到错误:

undefined不是对象(评估'this.toastInstance._root')

我认为这不是nativebase版本问题,我使用的是最新版本。提前致谢。

react-native react-redux native-base
2个回答
0
投票

要使Toast工作,您需要将最顶层的组件从native-base包装到<Root>中。


0
投票

只需删除代码中的return即可

© www.soinside.com 2019 - 2024. All rights reserved.