daronjay
daronjay

Reputation: 71

Is it possible to use redux-form without using connect()?

For various reasons that are not my call, in my work application, we are using redux without the connect HOC. There are pros and cons here. But is it possible to use redux-form in this manner, currently I have redux-form1 using it's own store viaconnect()`, which means it's less than ideal, there is at times state being passed between the two stores, the single source of truth is lost.

Is there any way I can use redux-form without using the connect HOC?

Upvotes: 4

Views: 811

Answers (3)

MechaCode
MechaCode

Reputation: 195

You can use reduxForm HOC. If you are using

semantic-ui-react,

then u can wrap fields by using <Form.Field>

Upvotes: 0

SimonStern
SimonStern

Reputation: 328

Redux forms uses reduxForm instead of connect, Here is an example.

NewCampaignForm.propTypes = {
  fields: PropTypes.object.isRequired,
  handleSubmit: PropTypes.func.isRequired,
  resetForm: PropTypes.func.isRequired,
  submitting: PropTypes.bool.isRequired
}

export default reduxForm({
  form: 'new-campaign-form',
  fields
})(NewCampaignForm);

And if you did want to, you could use connect on the parent container of that form, and it would work.

Upvotes: 0

Andy_D
Andy_D

Reputation: 4228

You don't need the react-redux connect HOC to use redux form. Redux form provides its own connect-like HOC called reduxForm. Wrap your form components with it using the config described in the link above, and you'll be good to go.

Upvotes: 1

Related Questions