Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
Toast messages in React - how to simply add a message to the Toaster?

I want to implement the Toast messages component. I have seen a few tutorials on that, but I don't quite understand how they add messages to the Toaster. I know how to do it with Redux or Context API, but is it possible without any of them? Most of these tutorials don't use them.

In my Toaster.jsx, I could do:

const Toaster = () => {
    const [toasts, setToasts] = useState([]);

    return (
        <ul>
            {toasts.map(({ id, message }) => (
                <Toast
                    key={id}
                    message={message}
                />
            ))}
        </ul>
    );
};

export default Toaster;

And then in some other component, I'd like to simply add toasts like this:

<button onClick={() => toast('Hello, world!')}>
    Display toast
</button>

What are the possible ways to communicate with the Toaster to make it add a message to its list of messages? Is it possible without wrapping any extra component on my App?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda