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

130
Views
REACCIONAR: Popover no muestra mi contenido json

En el menu/ no se muestra el nombre de mis invitados, solo aparece el InfoIcon de información en la celda. Quiero crear un Popover , cuando haces clic en el InfoIcon , obtienes toda la información de las personas invitadas (nombre y ubicación).

 export default function Display() { const { dishes } = JsonData; const [anchor, setAnchor] = useState(null); const openPopover = (event) => { setAnchor(event.currentTarget); }; const data = useMemo( () => [ ... { //Problem: participants not displayed and click not working Header: "Invited", id: "invited", accessor: (row) => row.invited.map(({ name }) => name).join(", "), Cell: (props) => ( <div> <InfoIcon /> <Popover open={Boolean(anchor)} anchorEl={anchor} anchorOrigin={{ vertical: "top", horizontal: "left" }} transformOrigin={{ vertical: "bottom", horizontal: "right" }} > <Typography variant="h1">{props.participants}</Typography> </Popover> </div> ) }, ], [] ); return ( <Table data={dishes} columns={data} /> ); }

Aquí está mi código

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Además de guardar el elemento en el que se hizo clic en el estado, de modo que el componente Popover tenga una referencia de elemento, también debe almacenar en el estado qué participantes de la fila específica se representarán en el popover. Actualmente, el código usa un valor booleano singular para todos los popovers. Use el row.id para abrir un popover específico.

No olvide agregar el estado "ancla" a la matriz de dependencia para que la ventana emergente obtenga el estado más reciente.

 function Display() { const { menus } = JsonData; const [anchorId, setAnchorId] = useState(null); const [anchorEl, setAnchorEl] = useState(null); const openPopover = id => (event) => { setAnchorId(id); setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorId(null); setAnchorEl(null); }; const data = useMemo( () => [ { Header: "Id", accessor: (row) => row.id }, { Header: "Invited", id: "invited", accessor: (row) => row.invited, Cell: (props) => ( <div> {props.value.map(({ name }) => name).join(", ")} <InfoIcon onClick={openPopover(props.row.id)} /> <Popover open={anchorId === props.row.id} onClose={handleClose} anchorEl={anchorEl} anchorOrigin={{ vertical: "top", horizontal: "left" }} transformOrigin={{ vertical: "bottom", horizontal: "right" }} > <Typography variant="h6"> {props.value.map(({ name, location }) => ( <div key={name}> <p>{name}</p> <p>Location: {location}</p> </div> ))} </Typography> </Popover> </div> ) }, { Header: "Title", accessor: (row) => ({ title: row.title, id: row.id }), Cell: ({ value }) => ( <Link to={{ pathname: `/menu/${value.id}` }}>{value.title}</Link> ) } ], [anchorEl, anchorId] ); const initialState = { sortBy: [ { desc: false, id: "id" }, { desc: false, id: "invited" }, { desc: false, id: "title" } ] }; return ( <Table data={menus} columns={data} initialState={initialState} withCellBorder withRowBorder withSorting withPagination /> ); }

Edite react-popover-doesnt-display-my-json-content

about 4 years ago · Santiago Trujillo 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!