Skip to content
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

Impossible to get form name within connect() #4735

Open
thany opened this issue May 28, 2021 · 1 comment
Open

Impossible to get form name within connect() #4735

thany opened this issue May 28, 2021 · 1 comment
Labels

Comments

@thany
Copy link

thany commented May 28, 2021

Impossible to get form name within connect()

When writing a component, you may need the form name, but not anything else. This is completely impossible. The only way is to use something like formValues(''), like so:

export default formValues('')(connect((state, props) => ({
  getFormAsyncErrors: getFormAsyncErrors(props._reduxForm.form)(state)
}))(MyComponent));

I can't always know the name of my form, can I? We've gor a million different forms, and a component, that might not be a Field, must be reusable within any form. Simple as that.

The above is a hack to achieve this. There is no other way to get to the form name within the connect() call. There should be a proper way to do this.

Your environment

Software Version(s)
redux-form 8.3.7
redux 4.0.5
react-redux 7.2.3
react 17.0.2
react-dom 17.0.2
node 14.17
npm if using whatever comes with Node.js
Browser Firefox latest
Operating System Windows 10

Steps to reproduce

Can't reproduce what's impossible, can I...

Expected behaviour

Opposite of actual behaviour.

Actual behaviour

See description.

Other information

Sorry to be short, but I just wasted 1,5 hours of fiddling around to figure out how to get the damn form name. It shouldn't be so hard. Also, I'm delibrately not issuing this as a feature request, because getting the form name is so utterly basic, that it probably just needs to be exposed, possibly by exporting withReduxForm.

@thany thany added the bug label May 28, 2021
@made-in-nz
Copy link

If you set your form name by passing a 'form' prop into your form component, rather than via reduxForm({form: 'xxx'}), it will be available from props within connect((state, props) => {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants