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.

Decorated form doesn't receive documented values instance prop

See original GitHub issue

According to: http://redux-form.com/6.2.0/docs/api/ReduxForm.md/

… in the section labeled Instance API the decorated component should have access to a values property, which should be

The current values of all the fields in the form.

But, no matter what I do, I can’t get the documented values property, either in my own code, or by pulling down the simple example and modifying it.

A simple example is conditionally rendering something in the form based on the current value, which seems like exactly what the documented values object would be ideal for.

import React from 'react'
import { Field, reduxForm } from 'redux-form'

const MyForm = ({ handleSubmit, values }) => (
  <form onSubmit={handleSubmit}>
    <div>
      <Field name="name" component="input" type="text"/>
      {values.name === 'Fred' && <b>Hi Fred!</b>} // <-- error! `values` undefined
    </div>
  </form>
);

export default reduxForm({ form: 'myForm' })(MyForm);

Or am I totally mis-understanding the documentation?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
martinhorskycommented, Nov 17, 2016

@jaredh159 Yes, you misunderstand docs and maybe what “instance” in React world means.

You are trying to get values from prop values. But it does not exists.

values you mentioned are available from instance of decorated component. To understand that, let’s see example:

import React from 'react'
import { Field, reduxForm } from 'redux-form'

const MyForm = ({ handleSubmit }) => (
  <form onSubmit={handleSubmit}>
    <div>
      <Field name="name" component="input" type="text"/>
    </div>
  </form>
);

export default reduxForm({ form: 'myForm' })(MyForm);
import React, { Component } from 'react'
import MyForm from './MyForm'

class MyContainer extends Component {

  componentDidMount() {
    console.log(this.form.values) // <-- here you can get values from instance of reduxForm
  }

  render() {
    <MyForm ref={ (instance) => { this.form = instance } } />
  }
}

That’s how Instance API works. You can see from example it’s designed for different usecase.

You should use what @niksajanjic suggests… formValueSelector + connect see: http://redux-form.com/6.2.0/examples/selectingFormValues/

I hope this explanation will help. 😀

0reactions
lock[bot]commented, Jun 2, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decorated form doesn't receive documented values instance ...
The current values of all the fields in the form. But, no matter what I do, I can't get the documented values property,...
Read more >
@prop | typegoose
Any Property that does not have @prop on it will not be in the Schema, because typegoose's current approach is that the keys...
Read more >
Documentation - Decorators - TypeScript
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use...
Read more >
Model validation in ASP.NET Core MVC | Microsoft Learn
The IsValid method accepts an object named value, which is the input to be validated. An overload also accepts a ValidationContext object, which ......
Read more >
Properties - Stencil.js
Properties. Props are custom attributes/properties exposed publicly on an HTML element. They allow developers to pass data to a component to render or ......
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