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
[React 15.2.0] Additional props warning #1249
Comments
I'm affraid this change will lead to a massive amount of issues created here... Unfortunately we can't do much to prevent this. One solution in v6 is to provide a new input component. const InputProps = [
// HTML attributes
"placeholder",
"type",
"value",
// Event listeners
"onBlur",
"onChange",
"onFocus",
]
const InputWrapper = props =>
React.createElement("input", _.pick(props, InputProps))
export default InputWrapper And to make it the default component of Field.defaultProps = {
component: InputWrapper,
} |
Another workaround is to instrument |
Results of first test:
It's amusing how accustomed whoever wrote that warning message is with GitHub Markdown that they used backquotes. |
What if you could do something like this: import { reduxForm, Field, filterProps } from 'redux-form'
const renderTextField = field =>
<div>
<input type="text" {...filterProps(field)}/>
// ^^^^^^^^^^^
{field.touched && field.error && <div>{field.error}</div>}
</div>
const MyForm = props =>
<form onSubmit={props.handleSubmit}>
<Field name="whatever" component={renderTextField}/>
</form>
export default reduxForm({ form: 'myForm' })(MyForm) Seems like the least a library designed to destructure objects into dom components could do... |
Maybe |
Is nesting the input-specific props an option? eg.
|
@tylergoodman That is an option, yes. |
@tylergoodman’s suggestion looks cleanest. |
@gaearon Stinks of "breaking change", though..... |
You could..
|
Ooh, for a moment there, I thought I might be clever and make the |
Nah, smart tricks are only going to make things worse. Please fix the underlying issue. 😉 |
I wasn't too fond of it it originally, but after implementing it, @tylergoodman's suggestion is growing on me. const renderField = field => (
<div>
<label>{field.input.placeholder}</label>
<div>
<input {...field.input}/>
{field.touched && field.error && <span>{field.error}</span>}
</div>
</div>
) The important thing is that the passthrough props go into the <Field name="username" component={renderField} type="text" placeholder="Username"/>
// Those guys ---> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Yea, IMO it’s the most elegant and clean solution. 👍 |
One unfortunate consequence is that <Field name="color" component={DropdownList} data={colors}/> Where as now, you have to pull the input props out for it with a: const renderDropdownList = field => <DropdownList {...field.input}/>
...
<Field name="color" component={renderDropdownList} data={colors}/> 😢 |
@erikras Seems like there's 3 possible behaviors:
You could handle this with extra props on
|
@jimbolla Excellent thinking! I've already implemented 1 and 3, but I definitely see some value in a |
This pattern is problematic and can lead to bugs. If third party |
I think being explicit about the props that are passed is the way to go -- everything else in react/redux tends to be explicit in the same way. (A good thing, IMO.) Making those props available on field.input makes a lot of sense to me. Before I found redux-form and I was starting to roll my own, an input sub-prop was what I came up with. So if I'm anything close to normal and a single piece of anecdotal evidence is worth anything, that's what I'd like to see. :) |
What about textareas or selects? For example, And even |
I getting the very same error , using Redux Form 5.2.5:
is there any way to get rid of this error, by downgrading to specific version of the library for example ? |
@padsbanger don't use react v15.2 for redux-form v5. Or omit all this props from every fields. |
|
Published fix in |
Sorry guys, I arrived super late to this party, but I wanted to bump @jasongonzales23's prior comment. My code is structured the same way as his with 6.0.0-rc3 (swapped out the [Update]: Durr, I'm an idiot, I see the v6 migration guide and using the |
@ericnograles thanks! Somehow I missed the migration guide. Will implement this soon! |
Sorry I'm a bit new on this but I followed the migration v6 guide to try to resolve the Unknown properties warning. All warnings are now gone, but my form is behaving super strange -- basically, I can manually focus an input element, type one character and then it suddenly loses focus! I re-focus the input using the mouse and can type normally. When I tab to next field, the same de-focus happens. But after the second time of manually re-focusing the input, this never happens again and I can type and tab between fields as normal. 100% replicable. This is my component:
|
OK, I've confirmed it's happening because instead of using a |
The redux-form v6 looks great but I'm still with problems using third-party inputs. The following code throws the warning:
I know some of the wrong properties come from the ReactPhoneInput but others are still from redux-form. |
@erikras, as @oliverchoy asked, is there any plan to fix this in v5? As v6 is not yet out it would be nice to have a v5 fix. |
v5 fix expected here too... |
+1 for fixing this in v5. #1444 shows why v5 is preferred over v6 currently |
Would love to have a v5 fix as well. Migrating to v6 isn't really feasible for the reason stated in #1444. |
Re: v5 props, @erikras has mentioned a workaround elsewhere, copied below. It'll silence the noise anyway. const domOnlyProps = ({
initialValue,
autofill,
onUpdate,
valid,
invalid,
dirty,
pristine,
active,
touched,
visited,
autofilled,
...domProps }) => domProps |
for v5 will the doc's be updated to reflect handling this issue? anyone have a v5 example to share of using this function to pass in our fields object? |
The workaround worked out perfectly. Thank you @elyobo for posting on this thread. |
@SOSANA it just picks out the extra fields that have meaning to const { fields: { myfield } } = this.props;
return <input {...domOnlyProps(myfield)} />; instead of const { fields: { myfield } } = this.props;
return <input {...myfield} />; |
@elyobo thanks for quick reply! worked as expected |
@elyobo Thanks for sharing the fix on this. The warning is gone in console now, but eslint is throwing errors due to no-unused-vars on each of the properties within domOnlyProps. Any suggestions for fixing this aside from disabling no-unused-vars for the file? |
@yourfavorite I disable that warning for this function; the unused vars are deliberate in this case, using destructuring to pick out the props that redux form cares about so that we can pass back everything else. My version looks like this - /* eslint-disable no-unused-vars */
// TODO: remove once upgraded to redux-form v6, which makes this redundant
export const domOnlyProps = ({
initialValue,
autofill,
onUpdate,
valid,
invalid,
dirty,
pristine,
active,
touched,
visited,
autofilled,
error,
...domProps,
}) => domProps;
/* eslint-enable no-unused-vars */ |
…field becasue of unknown props
Quite dumb proposal, but alternatively |
Async validation documentation this documentation is not updated with the v6 way of doing things (props under |
@glcheetham, you're looking at a way too old version of the docs! A lot of stuff changed since v6.0.0-rc.1. |
This change solves issue #3 that's caused by redux-form/redux-form#1249 .
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
It will be interesting to see, when React
15.2.0
is released, how many of these warningsredux-form
generates. More info and discussion here from the page the warning links to:Props like
valid
,invalid
,dirty
, andpristine
might cause warnings for cases where someone is just destructuring the field object into an input, i.e.<input type="text" {...firstName}/>
.The text was updated successfully, but these errors were encountered: