question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature Proposal: formValues() HOC decorator that works inside a form component

See original GitHub issue

From 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
gleb-lobastovcommented, Jul 21, 2017

@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

1reaction
gleb-lobastovcommented, Jun 18, 2017

@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 =(

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found