S
S
Sergey Suntsev2019-05-07 10:37:11
React
Sergey Suntsev, 2019-05-07 10:37:11

How to make a form title (redux-form) using props?

The page generates many dynamic forms.
form example:

import React, {Component} from 'react'
import Button from '@material-ui/core/Button'
import WysiwygTextarea from 'shared/ui/WysiwygTextarea'
import MaterialInput from 'shared/ui/MaterialInput'
import {reduxForm} from 'redux-form'

  render(){
    
    return(
      <form onSubmit={this.props.handleSubmit}>
        <WysiwygTextarea
          change={this.props.change}
          name="message"
          classes={'wysiwyg__component_chat'}
          toolbarClassName="demo-toolbar-absolute"
        />
        {this.props.key && <div className="dragon-form__field" style={{display : 'none'}}>
          <MaterialInput
            name="messageId"
          />
        </div>}
        <Button type="submit" variant="outlined">Отправить</Button>
      </form>
    )
  }
}

const validate = ({message}) => {
  const errors = {}
  if (!message) errors.name = 'Введите текст сообщения'
  return errors
}

export default reduxForm({
  form: 'room', // как вместо 'room' закинуть данные из props ?
  validate
})(ChatForm)

How to put data from props in the form name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-05-07
@GreyCrew

export default reduxForm({ validate })(ChatForm);
If you want to pass the name as the name property, then you can wrap the component in connect:

const mapStateToProps = (state, ownProps) => ({
  form: ownProps.name,
});

export default compose(
  connect(mapStateToProps),
  reduxForm({ validate }),
)(ChatForm);

<ChatForm name={name} />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question