Bug - the `useField` reads value before initialization
MiroslavPetrik opened this issue ยท comments
Describe the bug
the first render with useField()
does not use the value supplied in the initialValue
option.
To Reproduce
const field = fieldAtom<string>({ value: "" });
const FirstValueProp = () => {
const {
state: { value },
} = useField(field, { initialValue: "test" });
const [firstValueProp] = useState(() => value);
return <input value={firstValueProp} placeholder={value} />;
};
render(<FirstValueProp />);
the input placeholder
will have the value "test"
, while the input value
will have value ""
from the first render.
Expected behavior
the value
and placeholder
should have the same value.
Additional context
- This is problematic, when the value is forwarded to some uncontrolled components, which will be incorrectly initialized.
๐ This issue has been resolved in version 3.2.5 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐