在以下代码中,一旦选择文件,我希望在控制台中看到图像对象。但这并没有记录任何内容。也没有错误。
import React, { useState } from 'react';
const ImageUpload = () => {
const [image, setImage] = useState(null);
const handleChange = (e) => {
if (e.target.files[0]) {
setImage(e.target.files[0]);
};
};
console.log(image);
return (
<>
<input type='file' onChange={(e) => handleChange} />
</>
);
};
export default ImageUpload;
我在做什么错了?
答案 0 :(得分:1)
直接传递函数,无需创建内联函数
<input type='file' onChange={handleChange} />
答案 1 :(得分:0)
问题在这里:
Date dateDayBefore(char* inputDate)
{
struct tm dayBefore = { 0 };
char** fields = split(inputDate, 3, "/");
dayBefore.tm_mday = atoi(fields[0]);
dayBefore.tm_mon = atoi(fields[1]);
dayBefore.tm_year = atoi(fields[2]);
dayBefore.tm_mday--;
mktime(&dayBefore);
char yesterday[10];
strftime(yesterday, sizeof yesterday, "%d/%m/%Y", &dayBefore);
return dateCreate(yesterday);
}
您没有调用(e) => handleChange
函数。
更改为:
handleChange