Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
Unexpected function expression - ESLint error when using MUI Snackbar Component customized with Alert

I want to create a customized MUI Snackbar using MUI Alert by following the example in the official Documentation but ESlint is showing me this error:

error  Unexpected function expression  prefer-arrow-callback
error  Prop spreading is forbidden     react/jsx-props-no-spreading

in this part of the code:

const Alert = React.forwardRef(function Alert(props, ref) {
  return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

I used npx eslint . --fix to fix the issue but now I am getting:

error  Component definition is missing display name  react/display-name
error  Prop spreading is forbidden                   react/jsx-props-no-spreading

Here is My full code:

import * as React from 'react';
import Stack from '@mui/material/Stack';
import Button from '@mui/material/Button';
import Snackbar from '@mui/material/Snackbar';
import MuiAlert from '@mui/material/Alert';

const Alert = React.forwardRef(function Alert(props, ref) {
  return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

export default function CustomizedSnackbars() {
  const [open, setOpen] = React.useState(false);

  const handleClick = () => {
    setOpen(true);
  };

  const handleClose = (event, reason) => {
    if (reason === 'clickaway') {
      return;
    }

    setOpen(false);
  };

  return (
    <Stack spacing={2} sx={{ width: '100%' }}>
      <Button variant="outlined" onClick={handleClick}>
        Open success snackbar
      </Button>
      <Snackbar open={open} autoHideDuration={6000} onClose={handleClose}>
        <Alert onClose={handleClose} severity="success" sx={{ width: '100%' }}>
          This is a success message!
        </Alert>
      </Snackbar>
    </Stack>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

these are your eslint error

error  Unexpected function expression  prefer-arrow-callback
error  Prop spreading is forbidden     react/jsx-props-no-spreading
error  Component definition is missing display name  react/display-name

prefer-arrow-callback: use this => in the forward

const Alert = React.forwardRef((props, ref) => {
  return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});

react/display-name

const Alert = () => {
  .... 
}
Alert.displayName = "Alert";

react/jsx-props-no-spreading

if you don't want disable it you will have to list all the MuiAlert props and pass it through

const Alert = React.forwardRef((props, ref) => {
  const {
    action,
    children,
    classes,
    closeText,
    color,
    icon,
    iconMapping ,
    onClose,
    event,
    role,
    severity,
    sx,
    variant = "filled,
  } = props;
  return <MuiAlert ref={ref} elevation={6} variant={variant} action={action} ... />;
});

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda