Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the value or checked prop required in the ref? #1

Open
johnnyodonnell opened this issue Oct 18, 2017 · 5 comments
Open

Why is the value or checked prop required in the ref? #1

johnnyodonnell opened this issue Oct 18, 2017 · 5 comments

Comments

@johnnyodonnell
Copy link

(value !== undefined || checked !== undefined) &&

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?

@chrisblossom
Copy link
Owner

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.

@johnnyodonnell
Copy link
Author

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.

@chrisblossom
Copy link
Owner

chrisblossom commented Oct 25, 2017

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?

@chrisblossom
Copy link
Owner

@johnnyodonnell Is this still an issue? If not, how did you solve the problem?

@johnnyodonnell
Copy link
Author

johnnyodonnell commented Dec 5, 2017

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:

  1. Go to stacks.courses
  2. Fill out the sign up form but don't submit the form
  3. Click the login button even though it is empty (this will take you to a dedicated login page)
  4. Return back to the sign up form by either (a) clicking the Stacks logo or (b) clicking the "sign up here" link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants