This Is My Reactjs Passing Data Correctly
const[file ,setFile] = useState(null);
const handleFileChange = (e) =>{
const file = e.target.files[0];
if (file) {
const fileURL = URL.createObjectURL(file);
setFile(fileURL);
setProductData(prevState => ({
...prevState,
hinh_anh: file
}));
}
}
return(
<div>
<label>Hình Ảnh</label>
<input type='file' className='form-control' onChange={handleFileChange}/>
{file && <img src={file} alt="Preview" width="100" className='mt-2'/>}
</div>
{
<td><img src={`http://localhost:8081/uploads/${product.hinh_anh}`} alt='Product' width={100}/></td>
}
)
-
Help me fix the newly added image will be displayed not null
-
{`http://localhost:8081/uploads/${product.hinh_anh}`} // Is this link okay?
New contributor
Gia Minh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.