Open johnnyodonnell opened 7 years ago
If you are not using a value / checked prop, you are using an uncontrolled component. This library is only meant to fix a race condition with SSR + controlled components. See https://reactjs.org/docs/forms.html#controlled-components.
If I am misunderstanding your question / issue / wrong about controlled components, please provide a minimal example.
I'm using controlled components, but for a few specific inputs I don't have React setting the value.
For example, my password inputs have an onChange handler, but React doesn't set the value. This way if the user leaves the sign up page and comes back, the sign up form will have all fields filled in except for the password inputs.
This seems to be an uncommon use case, and possibly not a React recommended approach, but it does work pretty well for what I'm trying to accomplish.
I am still not sure that is a controlled component. So your goal with this library is to call onChange
in the event the input has changed prior to React being loaded?
I don't know how we'd see if a user has changed the value prior to React being loaded if the input state is not handled by React, but instead the native DOM. Maybe use a data attribute, such as data-initial-value
.
I think with your use case might be better served with a standard componentDidMount
and just clear the input every time the component is mounted.
Maybe I am still confused exactly how this input looks. Could you provide a minimal example?
@johnnyodonnell Is this still an issue? If not, how did you solve the problem?
This is still an issue. My workaround is to set the value attribute even though it's not the behavior I want.
I can give you an example to help better explain why I think the value attribute should be optional. The site I am building is stacks.courses
Steps:
Desired result: The sign up form shows with first name, last name, and email still filled in. And password and confirm password are blank.
Actual result: The sign up form shows first name, last name, email, password, and password confirm all filled in.
If value is not a required attribute then I believe I can achieve the desired result.
https://github.com/chrisblossom/react-safe-universal-inputs/blob/3e2b8b6c01f2dd3473a53c93887066bceea774c6/src/InputWrapper.js#L79
Currently my form inputs don't have value as a prop; and thus, this package does not work on my inputs. Is there a reason why value or checked is required?