【发布时间】:2019-11-11 16:58:42
【问题描述】:
我有以下代码
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>
由于某种原因,链接组件 category.id 为 1,但在句柄更改中,我只是在控制台记录 id 并返回 10(最后一个 category.id)这怎么可能?完整代码可以在这里找到https://pastebin.com/ZiDTkdTU
【问题讨论】:
-
请提供小提琴链接而不是 pastebin
标签: reactjs