'onClick in variables does not invoke the designated function

I am new to MUI and don't understand why this does not work:

const anlagendaten_array = [];

    for (let x = 0; x < anlagendaten.length; x++) {
        anlagendaten_array.push (
            <ListItem
                button
                key={anlagendaten[x].name}
                className="menu-unterpunkt"
                onClick={() => setOpen(false)}
            >
                <ListItemIcon>
                    <LocationOn fontSize="small" />
                </ListItemIcon>
                <ListItemText primary={anlagendaten[x].name} />
            </ListItem>
        )
    }

The onClick-function does not work. When using the <listIem>...</ListItem> at the place where I put {anlagendaten_array} it works.

Thx for any help

Oliver



Solution 1:[1]

Sorry for having bothered you. It was an I/O-error (Idiot Operator). When trying to build the codesandbox I realized my error. Thx to all helping around here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Odido