如何修复 nativebase toast 错误 undefined is not an object(评估“this.toastInstance._root”)

Lov*_* CG 5 react-native react-redux native-base

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

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

但是在调用此方法时出现错误:

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

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

nik*_*lyn 10

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