joethemow
joethemow

Reputation: 1773

Why is redux-form throwing an error?

I am trying to implement redux-form but I am coming across an error and can't seem to fix it or find the correct solution. Error: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.

import { Form, reduxForm } from 'redux-form';


    LocationInput({input, meta: { touched, error }, ...custom}) {
    return (
      <div>
        <input placeholder="Location..." type="text" />
      </div>
    );
  }

  render() {

    return (
      <Form name="locationInput" component={this.LocationInput} />
    )

 }

Upvotes: 1

Views: 919

Answers (2)

DroidNoob
DroidNoob

Reputation: 1143

You need to create a form component and export the formComponent using redux-form decorator

export default reduxForm({
  form: 'formName'  // a unique identifier for this form
})(formComponent)

Upvotes: 1

Erik R.
Erik R.

Reputation: 7272

You should not be using Form, unless you are doing some fancy submission via action dispatching. Look more at the examples.

You need to define a form component, decorate it with reduxForm(), and then put some <Field> elements inside it.

Upvotes: 1

Related Questions