Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toast.show is not a function (it is undefined)] #190

Open
shyammanek opened this issue May 8, 2024 · 6 comments
Open

toast.show is not a function (it is undefined)] #190

shyammanek opened this issue May 8, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@shyammanek
Copy link

shyammanek commented May 8, 2024

import { useToast } from "react-native-toast-notifications";

export default function Toast() {

const toast = useToast();

toast.show("Hello World");

}

Current behaviour

LOG error [TypeError: toast.show is not a function (it is undefined)]

Expected behaviour

Show Toast Notification

Code sample

For Syntax Highlighting check this link

Screenshots (if applicable)

What have you tried

Your Environment

software version
ios or android both
react-native 0.73.4
react-native-toast-notifications ^3.4.0
node
npm or yarn
@shyammanek shyammanek added the bug Something isn't working label May 8, 2024
@Somnus007
Copy link

I got the same problem~

@usmanabid94
Copy link

I am getting the same issue is there any specific reason for this or update on this issue?

@mahmingtea
Copy link

you are calling toast before it is loaded. Use it like this

const toast = useToast();
const isToastLoaded = () => {
    return Object.entries(toast).length === 0;
  };
useEffect(() => {
    if (!isToastLoaded()) {
      toast.show("Loading...")
     }
},[isToastLoaded()])

@yasiraktunc
Copy link

Can you fixed this bug

@arnnis
Copy link
Owner

arnnis commented Jun 11, 2024

toast must be called after initial render of application. i.e inside a useEffect(() => toast.show(), [])

@yasiraktunc
Copy link

export const ToastProvider: FC<PropsWithChildren> = ({children}) => {
  const toastRef = useRef(null);
  const [refState, setRefState] = useState(null);

  useEffect(() => {
    setRefState(toastRef.current as any);
    GlobalToast = toastRef.current as any;
  }, []);

  return (
    <ToastContext.Provider value={refState as any}>
      <Toast` ref={toastRef} />
      {refState && children}
    </ToastContext.Provider>
  );
};`
``` Override ToastProvider and  this is working true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants