I wrote the following code in React.
const onChangeImage = (e, setState) => {
const file = e.target.files[0]
if (e.target.files && e.target.files[0]) {
// 画像を格納
reader.onload = (data) => {
dispatch({
type: 'SET_SALON_DATA',
payload: {
title: e.target.name,
content: file
}
})
// this!!
}
reader.readAsDataURL(file)
}
}
At "this!!" point,which method is better? This state goes into the url of the img tag.
setState(URL.createObjectURL(file))
or
setState(data.target.result))
I'm waiting for your answer!