question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

twice loaded same time

See original GitHub issue

Hello

I use this component fkhadra/react-toastify, twice loaded for me same time, i want only once loaded other thing is correct and i dont have wrong or error on code writting , What is your solution ?

notify({type,text}){ toast(text, { position: "top-center", autoClose: 5000, hideProgressBar: false, closeOnClick: true, pauseOnHover: true, draggable: true, type: type }); }

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

18reactions
fkhadracommented, May 28, 2018

Keep the toast import in your component as follow:

import { toast } from 'react-toastify';
// omit the ToastContainer and the css

Then at the root of your app:

import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';

const App = () => (
  <div>
    <YourComponent />
    <ToastContainer />
  </div>
)

7reactions
areeburrubcommented, Oct 24, 2021

Hey @heshamelmasry77,

The toast function is probably called twice. You can provide a unique toastId to prevent duplicate. You can find how to here

This solution works

Yeah this solution works, just add a custom id and the toast won’t repeat

you may be using two type of Toasts Static and dynamic

For Static Toast

Simply add random text like this:

toast("Just a Toast", {toastId: "unique-random-text-xAu9C9-"});

For Dynamic Toast :

Dynamic toasts is used for notification or error logging so you can generate random unique id using this fumction:

//  Make ID function, I use this to create random ID
// credit : https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
const makeid = (length) => {
var result = '';
var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * 
charactersLength));
}
return result;
}

toast("Just a Toast", {toastId: makeid()});

Hope This Helped 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loaded Twice Baked Potatoes for Two - A Flavor Journal
Pop your twice baked potatoes back in the oven for about 10 minutes (this time at 350) to reheat them and melt the...
Read more >
Twice-Baked Loaded Potatoes Recipe by Tasty
Rub each potato with 1 teaspoon of oil, and prick the top with a fork. Place the potatoes on a rimmed baking sheet...
Read more >
Loaded Twice Baked Potatoes - Giant - David & Sons
Loaded Twice Baked Potatoes – Giant. $8.99. Huge potateos stuffed with bacon, cheddar, sourcream, & onion.
Read more >
Fully Loaded Twice Baked Potatoes Recipe
This easy twice baked potato recipe calls my name every time I look at it. You won't believe how creamy and delicious it...
Read more >
TWICE BAKED LOADED POTATOES || TERRI-ANN'S KITCHEN
Your browser can't play this video. Learn more. Switch camera.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found