I have the following code
const inputRef = useRef<HTMLInputElement>(null);
const handleClick = () => {
if (inputRef.current) inputRef.current.click();
};
return (
<Container fixed>
<div className={classes.root}>
<Grid container spacing={1}>
{data &&
data.map(category => (
...
<Link to={`/products/${category.id}`}>
...
<input
accept="image/*"
hidden
type="file"
ref={inputRef}
onChange={e => handleChange(e, category.id)}
/>
<IconButton onClick={handleClick}>
<InsertPhoto />
</IconButton>
For some reason, the Link component category.id is 1 but in handle change, I simply console log the id and it returns 10 (the last category.id) how is this possible? the full code can be found here https://pastebin.com/ZiDTkdTU