Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript, redux-form and connect

First of all, I'm very new to TS, React & Redux, so sorry if this is an obvious question.

I'm trying to modify this example to get a form to load some information. It's using redux-form.

I'm trying to figure out how to call connect and redux-form at the same time in the export of the component. Right now it's looking like this:

class UserForm extends React.Component<IUserProps, void> { .. }

export default ReduxForm.reduxForm({
  form: 'user',
  fields: [
    'userName',
    'password',
    'firstName',
    'lastName',
    'email'
  ],
  validate: UserForm.validate,
})(UserForm);

The examples I've seen without TS look like this:

class MyForm extends Component {}
MyForm = reduxForm(config)(MyForm)
MyForm = connect(mapStateToProps, mapDispatchToProps)(MyForm)
export default MyForm

But if I try to do the same in TS I get the TS2300 error: duplicate identifier.

I've also tried to use the @connect decorator, but I couldn't make it work (or find any working example online).

like image 667
LeoLozes Avatar asked Nov 21 '16 14:11

LeoLozes


1 Answers

Can you just chain them?

class UserForm extends React.Component<IUserProps, void> { .. }

export default connect(mapStateToProps,mapDispatchToProps) 
    (ReduxForm.reduxForm({
  form: 'user',
  fields: [
    'userName',
    'password',
    'firstName',
    'lastName',
    'email'
  ],
  validate: UserForm.validate,
})(UserForm));
like image 95
Alejandro C. Avatar answered Oct 27 '22 09:10

Alejandro C.