Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toastify Reactjs adding a link

How do I add a link like 'Click here to view' in reactjs toastify and link it to some other url? Currently I can only add static text to it. I used:

toast.info('some text')

And I want to display another line saying click here to view with a href property

like image 641
Amulya Dubey Avatar asked Jan 24 '23 21:01

Amulya Dubey


1 Answers

You can toast with react components.

Toast API

const CustomToastWithLink = () => (
  <div>
    <Link to="/toasttest">This is a link</Link>
  </div>
);

Toast by toast.info(CustomToastWithLink);

Example Usage

import React from "react";
import { BrowserRouter as Router, Link, Switch, Route } from "react-router-dom";
import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";

const CustomToastWithLink = () => (
  <div>
    <Link to="/toasttest">This is a link</Link>
  </div>
);

const Home = () => {
  const letsToast = () => {
    toast.info(CustomToastWithLink);
  };
  return (
    <div>
      <h3>Home</h3>
      <button type="button" onClick={letsToast}>
        Toast!
      </button>
    </div>
  );
};

const ToastTest = () => (
  <div>
    <h3>Toast Test</h3>
    Toast Test Satisfactory
  </div>
);

export default function App() {
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>

      <Router>
        <Switch>
          <Route path="/toasttest" component={ToastTest} />
          <Route component={Home} />
        </Switch>
        <ToastContainer />
      </Router>
    </div>
  );
}

Edit Custom Toastify Toast with React Component

like image 199
Drew Reese Avatar answered Feb 22 '23 05:02

Drew Reese