Before updating profile picture, I want to preview it. So, here I use function to preview and submit it. But, this two of task can't be do in one fuction. If you know how to do it. Please help me.
<div class="mb-3">
<label for="formFile" class="form-label">
{" "}
<strong> Profile Picture</strong>{" "}
</label>
<div className="row">
<div className="col-sm-4">
<img className="img shadow" src={file} alt="select image" />
</div>
<div className="col-sm-8">
<input
class="form-control"
type="file"
id="file"
filename="file"
onChange={onChangeFile}
required
/>
</div>
</div>
</div>
this is the function i used
const onChangeFile = (e) => {
setfile(e.target.files[0]);
const [file] = e.target.files;
setfile(URL.createObjectURL(file));
// if (e.target.files && e.target.files[0]) {
// setfile(URL.createObjectURL(e.target.files[0]));
// setfile(e.target.files[0]);
// }
};