Skip to content

Stateless function components cannot be given refs #188

@ketysek

Description

@ketysek

Hi, I'm using lib v. ^5.0.0-beta.1 and getting following error when I insert a text field:

Stateless function components cannot be given refs. Attempts to access this ref will fail.
Check the render method of ReduxFormMaterialUITextField.

What I'm doing wrong? Is it bug? My code is below:

import React, { Component } from 'react'
import { reduxForm, Field } from 'redux-form'
import Button from 'material-ui/Button'
import { FormControlLabel } from 'material-ui/Form'
import { Switch, TextField } from 'redux-form-material-ui'

class UserForm extends Component {
  onSubmit(data) {
    this.props.onSubmitAction(data)
  }

  onCancelButtonClick() {
    const { handleRequestClose } = this.props
    if(handleRequestClose) {
      handleRequestClose()
    }
  }

  render() {
    const { handleSubmit } = this.props
    const isCreate = this.props.actionType === 'create'
    const isUpdate = this.props.actionType === 'modify'

    return (
      <Grid container alignItems='center' justify='center'>
        <Grid item xs={12}>  
          <Paper className="form in-drawer" elevation={ 0 }>
            { isCreate && <h3>Add a new User</h3> }
            { isUpdate && <h3>Modify user</h3> }
            <form autoComplete="off" onSubmit={ handleSubmit(this.onSubmit.bind(this)) }>
              <Field
                name="name"
                component={ TextField }
                label="Name *"
              />
              { isUpdate &&
                <FormControlLabel 
                  control={
                    <Field name="disabled" component={Switch} /> 
                  } 
                  label="Disabled" 
                />
              }
              <Typography type="button" className="button-area inverted">
                <Button className="submit" raised color="primary" type="submit"> 
                  {isCreate && 'Create'}
                  {isUpdate && 'Modify'}
                </Button>
                <Button className="back" raised color="default" onClick={ this.onCancelButtonClick.bind(this) }>
                  Cancel
                </Button>
              </Typography>
            </form>
          </Paper>
        </Grid>
      </Grid>
    )
  }
}

UserForm = reduxForm({
  form: 'UserForm',
  touchOnBlur: false
})(UserForm)

export default UserForm

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions