Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix nativebase toast error undefined is not an object (evaluating 'this.toastInstance._root')

I am using nativebase ("native-base": "^2.12.1") at react-native project. I gonna use show toast on the method in react component class

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

But I am getting an error at calling this method:

undefinded is not an object (evaluating 'this.toastInstance._root')

I think this is not nativebase version issue, I am using the latest version. Thanks in advance.

like image 687
Loveun CG Avatar asked Mar 19 '19 12:03

Loveun CG


3 Answers

For Toast to work, you need to wrap your topmost component inside <Root> from native-base.

like image 50
nikelyn Avatar answered Oct 01 '22 22:10

nikelyn


import Root from "native-base";

import Root from native base and wrap the whole container/view inside render's return function

render() {
    return (<Root>your app-return function code</Root>);}
like image 36
Khaja Nizamuddin Avatar answered Oct 02 '22 00:10

Khaja Nizamuddin


Import Root component from native-base and wrap the entire app in it. This worked for me after days of looking for solution. Wonder why it wasn't stated in the docs

like image 26
Oluwaseyitan Baderinwa Avatar answered Oct 02 '22 00:10

Oluwaseyitan Baderinwa