Socket
Socket
Sign inDemoInstall

react-native-fast-toast

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-fast-toast

[![Version][version-badge]][package] [![MIT License][license-badge]][license]


Version published
Weekly downloads
2.2K
increased by73.36%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-fast-toast

Version MIT License

A Toast component for react-native, supports Android, IOS, Web, Windows

Features

  • Normal, Success, Danger and Warning toasts
  • Customizable and Icon support
  • Smooth animation
  • Fully typed with TypeScript

Demo

Install

Open a Terminal in the project root and run:

yarn add react-native-fast-toast

Basic Example

import React, { useEffect, useRef } from "react";
import Toast from "react-native-fast-toast";

export default function App() {
  const toast = useRef(null);

  useEffect(() => {
    toast.current.show("Task finished successfully");
  }, []);

  return (
    <>
      <RestOfYourApp />
      <Toast ref={toast} />
    </>
  );

Hook Example

You can use hooks to call toasts everywhere, to do so, wrap ToastProvier to your root component (index.js or App.js)

import { ToastProvider } from 'react-native-fast-toast'

export default function App() {
  return (
    <ToastProvider>
      <RestOfYourApp />
    <ToastProvider/>
  );
}

Then use hook like this everywhere in your app:

import { useToast } from 'react-native-fast-toast'

const Component = () => {
  const toast = useToast()
}

Global Example

Alternatively, To call toasts everywhere (even outside of React components like in redux actions), do this in root component of your app (index.js or App.js)

import Toast from "react-native-fast-toast";

export default function App() {
  return (
    <>
      <RestOfYourApp />
      <Toast ref={(ref) => global['toast'] = ref} />
    </>
  );

Now you can call toast.show() everywhere on app. like alert.

TypeScript Note: add index.d.ts to your project root.

Type Example

toast.show("Task finished successfully", { type: "success" });

Icon Example

toast.show("Task finished successfully", { icon: <Icon /> });

or

<Toast
  ref={toast}
  icon={<Icon />}
  successIcon={<SuccessIcon />}
  dangerIcon={<DangerIcon />}
  warningIcon={<WarningIcon />}
/>
}

Customize

toast.show("Task finished successfully", {
  duration: 5000,
  style: { padding: 0 },
  textStyle: { fontSize: 20 },
});

You can customize default options in Toast component

<Toast 
  duration={5000} 
  textStyle={{ fontSize: 20 }}
  successColor="green"
  dangerColor="red"
  warningColor="orange"
  normalColor="gray"
/>

Placement

<Toast
  placement="bottom | top" // default to bottom
  offset={50} // distance from bottom or top. ( default to 60 )
/>

Contributing

Pull request are welcome.

While developing, you can run the example app to test your changes.

Donation

If this project helped you reduce time to develop, you can buy me a cup of coffee :)

Buy Me A Coffee

Hire

Looking for a React/React-Native Expert? Email at alirezarzna@gmail.com

License

MIT

Keywords

FAQs

Package last updated on 01 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc