Feature Proposal: formValues() HOC decorator that works inside a form component
See original GitHub issueFrom discussion on #2852 with @wmertens. The problem being solved is that formValueSelector()
cannot be used in a reusable way inside a <FormSection>
because it doesn’t know what the prefix defined in the <FormSection>
is. General API syntax would look like:
@formValues({
destProp: 'nameOfField'
})
class MyReusableFields extends Component {
render() {
const { destProp } = this.props
// destProp is the value of the field called 'nameOfField'
return (
<div>
<Field name="nameOfField" component="input"/>
... other fields
... some logic involving value of nameOfField:
{destProp === 'specialValue' && <div>Value is SPECIAL!!</div>}
</div>
)
}
}
There might also be an alternative syntax where, if your keys and values were all going to be the same, rather than pass…
@formValues({
firstField: 'firstField', // key and value are ===
secondField: 'secondField' // key and value are ===
})
class MyReusableFields extends Component {
...
}
…you could just pass a list of strings. e.g.
@formValues('firstField', 'secondField')
class MyReusableFields extends Component {
...
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:14 (8 by maintainers)
Top Results From Across the Web
FormSection and nested Field component bug · Issue #2852
When using FormSection with nested Field components, input names get ... Feature Proposal: formValues() HOC decorator that works inside a ...
Read more >Redux Form - Getting Started
A React component decorator that wraps your entire form in a Higher Order Component (HOC) and provides functionality via props. A Field component...
Read more >TypeScript HOC (Higher-Order Component) and ...
You are going to learn how to build a HOC for React using TypeScript. We are going to develop a Higher-Order Component that...
Read more >Managing Form State in React With Redux Form
It is a Higher-Order-Component (HOC) that uses react-redux to make sure HTML forms in React use Redux to store all of its state....
Read more >Higher-Order Components
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@wmertens finally I reproduce the issue: https://codesandbox.io/s/Vrn7MZov
And root of problem was in my react-redux version: 4.4.5 if you change react-redux to latest 5^ then problem will gone
@erikras I face some strange behaviour with formValues: values lagging behind the state at the time of reading. getValues retun { flag: false } when it actually true in the state. They syncs only on next mapStateToProps calculation, which might be performed only at next user interaction.
So formValuesSelector works for me, but formValues does not =(