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

callable types unhandled? #26

Closed
rosskevin opened this issue Jun 18, 2016 · 9 comments
Closed

callable types unhandled? #26

rosskevin opened this issue Jun 18, 2016 · 9 comments

Comments

@rosskevin
Copy link
Contributor

rosskevin commented Jun 18, 2016

I receive Warning: Failed propType: Required prop onBlur was not specified in TextField.

This flow code:

declare function ValueHandler (value:string):void

type Props = {
  value:?any,
  name:string,
  errors:?any,
  onChange:ValueHandler,
  onBlur:ValueHandler
}

type State = {}

class TextField extends Component<void, Props, State> {
  log:Logger = new Logger(this)
  props:Props
  state:State;
}

Generates:

TextField.propTypes = {
      value: __webpack_require__(4).PropTypes.any,
      name: __webpack_require__(4).PropTypes.string.isRequired,
      errors: __webpack_require__(4).PropTypes.any,
      onChange: __webpack_require__(4).PropTypes.any.isRequired,
      onBlur: __webpack_require__(4).PropTypes.any.isRequired
    };

The onChange and onBlur are specified, not null, and of the signature I have specified.

Am I missing something or is this not yet supported?

@marcusdarmstrong
Copy link
Contributor

That warning is in how you're using TextField, not the generated proptypes.

@rosskevin
Copy link
Contributor Author

hmmm, here's a gist (I'm working on an integration with react-formal): https://gist.github.com/rosskevin/e166b1a174f961ac61a091930dfcefa7

Do you spot the misuse?

@rosskevin
Copy link
Contributor Author

maybe related: reduxjs/react-redux#6

es7 use?

@marcusdarmstrong
Copy link
Contributor

You're not specifying an onChange or onBlur here: https://gist.github.com/rosskevin/e166b1a174f961ac61a091930dfcefa7#file-signin-js-L71

@rosskevin
Copy link
Contributor Author

rosskevin commented Jun 18, 2016

That's a react-formal Field. I register my TexField as a handler for password, and Field passes those props to TexField.

Effectively:

<Field>
  <TextField {...this.props} onChange={x} onBlur={x} />
</Field>

@marcusdarmstrong
Copy link
Contributor

Right. But you never pass those props to Form.Field. So it never passes them to TextField.

There's nothing in here: https://github.com/jquense/react-formal/blob/master/src/Field.jsx that's going to pass an onBlur or onChange handler to your TextField without it having been passed to the Form.Field.

@rosskevin
Copy link
Contributor Author

rosskevin commented Jun 18, 2016

Maybe I'm not describing it well. I don't want to/intend to pass these handlers...ever. react-formal Form.Field dynamically connects the Form's handlers (onChange && onBlur) and passes them and other information to my TextField. My client code (Signin) needs no knowledge of these handlers.

I know with certainty that TextField is receiving these handlers and they are not null.

Here (my TextField is Widget) is instantiated by Form.Field: https://github.com/jquense/react-formal/blob/master/src/Field.jsx#L426

I don't spot onBlur specified as a required propType in react-formal Field. Is this the source of the Warning? That we have a broken chain of requires? Meaning I am receiving them, but the propTypes don't guarantee it based on them being missing in react-formal Field?

@marcusdarmstrong
Copy link
Contributor

Ah, didn't realize it was context aware to the Form. But even so, your Form doesn't have an onBlur, so I don't know what your password field would be receiving for that prop.

And no, propTypes are runtime checks. There's nothing static about them/no guarantees of any kind, so if you're getting a warning from them (as you are here), the warning is indicating a specific example of a runtime type check (in this case, your onBlur prop not being provided) failing.

@rosskevin
Copy link
Contributor Author

Ok, thanks much for the look, helps my understanding. I'll figure out where/when/why it is missing, certainly if the check is implemented, it's a good warning!

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