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

125
Vistas
Unexpected Snackbar+Alert behavior

Why is this throwing an error:

import Snackbar from "@mui/material/Snackbar";
import MuiAlert from "@mui/material/Alert";
const Alert = ({children}) => <MuiAlert>{children}</MuiAlert>

<Snackbar open>
    <Alert>test</Alert>
</Snackbar>

(but this is not?)

import Snackbar from "@mui/material/Snackbar";
import MuiAlert from "@mui/material/Alert";

<Snackbar open>
    <MuiAlert>test</MuiAlert>
</Snackbar>

In my understanding, they should both work the same.

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

When you're using single line component syntax, you don't need to use return keyword for getting back the component. Just => is enough:

import Snackbar from "@mui/material/Snackbar";
import MuiAlert from "@mui/material/Alert";
const Alert = ({children}) => <MuiAlert>{children}</MuiAlert>

export default function App() {
  return (
    <>
      <Snackbar open>
        <Alert>test</Alert>
      </Snackbar>
    </>
  );
}
about 4 years ago · Santiago Trujillo Denunciar

0

It turns out I needed to pass the ref using React.forwardRef to the Alert:

import Snackbar from "@mui/material/Snackbar";
import MuiAlert from "@mui/material/Alert";
const Alert = React.forwardRef(({children}, ref) => <MuiAlert ref={ref}>{children}</MuiAlert>)

<Snackbar open>
    <Alert>test</Alert>
</Snackbar>
about 4 years ago · Santiago Trujillo Denunciar
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