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

Control component fallback to empty string breaks type strict code #6

Open
EricMcRay opened this issue Jan 15, 2020 · 2 comments
Open

Comments

@EricMcRay
Copy link

get value(): any { return this.context.form.getValue(this.props.name) || ''; }

As you can see above link. if form value is falsy control component fallbacks to empty string. This misdirects to developers and causes to break type strict codes.

For example; A react native date picker component requires value as Date object or undefined and control value fallbacks to empty string when passed value undefined for an unselected date. Due to react-native, it crashes the app because native code expects Date object.

@unexge
Copy link
Owner

unexge commented Jan 15, 2020

added defaultValue prop to Foect.Control for backward compatibility (defaults to empty string), can you try <Foect.Control defaultValue={undefined} ...> with version 0.1.6?

@EricMcRay
Copy link
Author

I think this can make it worse. Looks like this increases inconsistency with form default value and make things more complicated. I would prefer giving fallback value explicitly from form values.

My current solution for now:

      <Foect.Form
        defaultValue={{
          email: '[email protected]',
        }}
      >
        {form => (
          <Foect.Control>
            {control => (
                <Input value={control.value || form.getValue('email')}></Input>
            )}
          </Foect.Control>
        )}
      </Foect.Form>

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