final-form / final-form/react-final-form

useField sets `type` to `undefined` when not provided via FieldRenderProps

Open
#624 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.4k
Forks
497
PR merge metrics
No merged PRs in 30d

Description

Oh hey @erikras! Long time no chat. =P

Finally am getting to use this!

### Are you submitting a **bug report** or a **feature request**?

Bug!

### What is the current behavior?

`useField()` returns `input: { ...stuff, type: undefined }`

### What is the expected behavior?

Instead, the key should _not be deifined_

### Sandbox Link

https://codesandbox.io/s/react-final-form-simple-example-p35vk

### What's your environment?

react-final-form@6.3.0

### Other information

The reason this is problematic is that, when spreading into something, it will override `type: 'something'` with `type: undefined` since the key's value is actually set to `undefined`. This is due to a bad optimization in the compiled output:

```

function useField(name, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
afterSubmit = _ref.afterSubmit,
allowNull = _ref.allowNull,
beforeSubmit = _ref.beforeSubmit,
component = _ref.component,
defaultValue = _ref.defaultValue,
_ref$format = _ref.format,
format = _ref$format === void 0 ? defaultFormat : _ref$format,
formatOnBlur = _ref.formatOnBlur,
initialValue = _ref.initialValue,
isEqual = _ref.isEqual,
multiple = _ref.multiple,
_ref$parse = _ref.parse,
parse = _ref$parse === void 0 ? defaultParse : _ref$parse,
_ref$subscription = _ref.subscription,
subscription = _ref$subscription === void 0 ? all$1 : _ref$subscription,
type = _ref.type,
validate = _ref.validate,
validateFields = _ref.validateFields,
_value = _ref.value;
```

In the uncompiled code, there is a check for `undefined` before assigning to the key. In compiled code, that check is not there, and it explicitly sets `type` to `_ref.type`, which is undefined by default.

I haven't looked at this build on why this is.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.