I made input used {useform} library.
It was appropriate to use many "input".
However, the image preview "Enter" does not work. I tried to preview the image. I hope you get help.
background-image: url(null); It's printed.
import { useForm, Controller } from 'react-hook-form';
import Select from 'react-select';
const SingleInput = () => {
return(
const [fileUrl, setFileUrl] = useState(null);
const saveFileImage = event => {
const imageFile = event.target.files[0];
const imageUrl = URL.createObjectURL(imageFile);
setFileUrl(imageUrl);
};
<label>
add Media
<input
type="file"
onChange={saveFileImage}
accept="image/*"
{...register('file')}
/>
</label>
<div
style={{
backgroundImage: `url(${fileUrl})`,
}}
/>
)
Thats because your onChange method on input is overrided by onChange from register(). Try to get data from useForm itself or wrap input in Controller, so you can customize this behaviour.