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

146
Views
React function is always called with same parameter in a loop

I have a data array and display its elements in table rows. The last table cell includes a menu item which calls a function with parameter. The problem is that function handleOpenApproveDialog is always fired with same data element, the last element of myData array.

CodeSandbox link

  const handleOpenApproveDialog = (ev, item) => {
    setAnchorEl(null);
    dispatch(openApproveDialog(item));
    //* problem: incoming item parameter is always same. The last element of myData array.
  };

  <TableBody>
    {myData.map((n, i) => {
      return (
        <TableRow
          tabIndex={-1}
          key={i}
          onClick={(event) => handleRowClick(event, n)}
        >

          <TableCell className="p-4 md:p-16" component="th" scope="row">
            {n.company}
          </TableCell>

          <TableCell
            className="p-4 md:p-16"
            component="th"
            scope="row"
            align="right"
          >
            <IconButton
              aria-label="actions"
              id="actions-button"
              aria-controls={isMenuOpen ? "actions-menu" : undefined}
              aria-expanded={isMenuOpen ? "true" : undefined}
              aria-haspopup="true"
              onClick={(ev) => {
                handleMenuClick(ev);
                ev.stopPropagation();
              }}
            >
              <MoreVertIcon />
            </IconButton>
            <Menu
              id="actions-menu"
              anchorEl={anchorEl}
              open={isMenuOpen}
              onClose={handleMenuClose}
            >
              <MenuItem
                onClick={(ev) => {
                  handleOpenApproveDialog(ev, n);
                  ev.stopPropagation();
                }}
              >
                Approve
              </MenuItem>
            </Menu>
          </TableCell>
        </TableRow>
      );
    })}
  </TableBody>
about 4 years ago · Juan Pablo Isaza
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!