Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

254
Views
Expresión de función inesperada: error de ESLint al usar el componente MUI Snackbar personalizado con Alert

Quiero crear un MUI Snackbar personalizado usando MUI Alert siguiendo el ejemplo en la Documentación oficial pero ESlint me muestra este error:

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

en esta parte del código:

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

npx eslint . --fix para solucionar el problema, pero ahora obtengo:

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

Aquí está mi código completo:

 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 answers
Answer question

0

estos son tus errores de eslint

 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: usa esto => en el reenvío

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

reaccionar / mostrar-nombre

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

reaccionar/jsx-props-sin-propagación

si no desea deshabilitarlo, deberá enumerar todos los accesorios de MuiAlert y pasarlo

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!