npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-gtoast

v0.0.2

Published

Global Toast for react-native

Downloads

10

Readme

react-native-gtoast

A React Native Global Toast that can be called from anywhere within your project.

Why Another Toast Package?

I needed a global Toast that I can call from anywhere within my project (similarly to Alert.alert(title, message?, buttons?, options?)) and especially from Redux async actions (Redux Thunk) whereas most of the existing Toast packages require to add a Toast component inside every component you want it display a toast and set the Toast component a refto be used to interact with it. Thus, it's going to be hard to access it from a Redux Thunk action.

Install

npm install --save react-native-gtoast

Example

This an example Redux Thunk action that shows a Toast wether a comment is added or failed to add.

import { showToast } from 'react-native-gtoast';
import axios from 'axios';

// ...

export const addCommentAction = () => {
	return (dispatch) => {
		dispatch({ type: 'ADD_COMMENT_START' });

        return axios.post('/post/1/comments').then(
			(comment) => {
                dispatch({ type: 'ADD_COMMENT_SUCCESS', comment });

                showToast('Comment added!', {
                    duration: 1200
                })
            },
			(err) => {
                dispatch({ type: 'ADD_COMMENT_FAILURE', err });

                showToast('There was an error adding comment!', {
                    duration: 3000
                })
            }
		);
	};
};

Note: A <GToastContainer> must be added in your app root component. (Read more)

Documentation

Toasts Container

All toasts are going to be rendered inside a <GToastContainer> component that we should explicitly add in our app root component.

Preferably, it should be wrapped inside a Fragment. It's also fine to wrap it inside the Redux <Provider> component if applicable.

You should AVOID wrapping the <GToastContainer> inside the core react-native components such as <View>, <ScrollView>, <SafeAreaView>, etc and any component that could have such style props width, height, position and so on.

import React, { Fragment } from 'react';
import { GToastContainer } from 'react-native-gtoast';
import HomeScreen from './components/Home';

export default function App() {
    return (
        <Fragment>
            <HomeScreen />
            <GToastContainer paddingBottom={30} />
        </Fragment>
    );
}

<GToastContainer />

ReactNode The toasts container.

Props

| Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | paddingBottom | number | 0 | The padding from the bottom. |

showToast()

showToast(text: string, options?: ToastOptions)

method Shows a toast.

Parameters

| Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | text (required) | string | - | The toast message. | | options | ToastOptions | See ToastOptions Reference | The toast options. |

ToastOptions

{
    id?: string,
    duration?: number
}

Object Toast options.

Props

| Name | Type | Default | Description | | ---- | ---- | ------- | ----------- | | id | string | null | The toast unique ID. | | duration | number| 3000 | The toast display duration in milliseconds. |

Usage

Basic

Everytime the button will be pressed, a toast will be created and displayed.

import React from 'react';
import { View, Button } from 'react-native';
import { showToast } from 'react-native-gtoast';

export default function App() {
    const handlePress = () => {
        showToast('Awesome Global Toast!');
    };

    return (
        <View>
            <Button title={'Show my Toast'} onPress={handlePress} />
        </View>
    );
}

Unique Toasts

It doesn't matter how many times we press the button, it will create and display the toast once unless the toast is disappeared.

showToast('Awesome Global Toast!', {
    id: 'my-awesome-toast'
});

License

Licensed under the MIT license.