Loveun CG
Loveun CG

Reputation: 99

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.

Upvotes: 5

Views: 4723

Answers (4)

Khaja Nizamuddin
Khaja Nizamuddin

Reputation: 177

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>);}

Upvotes: 4

jim gitonga
jim gitonga

Reputation: 128

import ROOT and import ROOT from 'native-base' the wrap the to <Root>{YOUR FUNCTION}</Root>

Upvotes: 1

Oluwaseyitan Baderinwa
Oluwaseyitan Baderinwa

Reputation: 1137

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

Upvotes: 3

nikelyn
nikelyn

Reputation: 548

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

Upvotes: 10

Related Questions