I am trying to have an initial value in my input field before the user edits it. But when an initial value is given, it does erase when I try to remove it.
<Input
type="text"
placeholder={
title === "" && fieldsFilled === false
? "This is a required field"
: "Enter Title"
}
id="title"
onChange={(e) => setTitle(e.target.value)}
style={
title === "" && fieldsFilled === false
? styles
: null
}
/>
Why is my state not updating when I change. What is wrong with the onChange?
Dont add initial value on placeholder use value to add it and initial value should come from hook as below
const [title, setTitle] = useState('initial value')
<Input
type="text"
placeholder={
title === "" && fieldsFilled === false
? "This is a required field"
: "Enter Title"
}
id="title"
value = {title}
onChange={(e) => setTitle(e.target.value)}
style={
title === "" && fieldsFilled === false
? styles
: null
}
/>
look on how i added the value = {title} on input tag, thats the key