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

How to scale multiple forms? #16

Closed
steven-haddix opened this issue Nov 27, 2016 · 3 comments
Closed

How to scale multiple forms? #16

steven-haddix opened this issue Nov 27, 2016 · 3 comments
Labels

Comments

@steven-haddix
Copy link
Contributor

I'm playing through the universal redux example and I'm curious what the proper way to scale the application to have potentially dozens of forms?

Would you reuse the forms actions but have a different container for each form?

@diegohaz
Copy link
Owner

Hi, @steven-haddix

I create a container and an organism component for each form, reusing the Field component.

I can give you a better answer if you share the snippet of code you are doing.

@steven-haddix
Copy link
Contributor Author

I don't have anything in a repo just yet. Mostly exploring the architecture and seeing how things work.

Do the forms all share the same store/form functions?

@diegohaz
Copy link
Owner

diegohaz commented Nov 29, 2016

Do the forms all share the same store/form functions?

They share some, but not all. A PostCreationForm, for example, calls postCreate from store; a LoginForm would call something from an auth store; and so on.

import { connect } from 'react-redux'
import { reduxForm } from 'redux-form'
import { postCreate, fromForm } from 'store'
import { createValidator, required } from 'services/validation'

import { PostForm } from 'components'

const onSubmit = (data, dispatch) => new Promise((resolve, reject) => {
  dispatch(postCreate.request(data, resolve, reject))
})

const validate = createValidator({
  title: [required],
  body: [required]
})

const mapStateToProps = (state) => ({
  initialValues: {
    _csrf: fromForm.getCsrfToken(state)
  }
})

export const config = {
  form: 'PostForm',
  fields: ['title', 'body'],
  destroyOnUnmount: false,
  onSubmit,
  validate
}

export default connect(mapStateToProps)(reduxForm(config)(PostForm))

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