react-select icon indicating copy to clipboard operation
react-select copied to clipboard

Component crashes

Open robertkowalski opened this issue 10 years ago • 27 comments

Hi and thanks for react-select!

I want to use react-select in apache/couchdb-fauxton

The component renders if I disable it:

          <Select
            ref="stateSelect"
            disabled={true}
            options={options} />

However when I enable it, it crashes with:

Warning: React.createElement: type should not be null, undefined, boolean, or number. It should be a string (for DOM elements) or a ReactClass (for composite components). Check the render method of `Select`.

Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. Check the render method of `Select`.

I already tried a lot of things to fix it, but I am quite puzzled now. Here is the full code which crashes:

  var STATES = [
    { value: 'australian-capital-territory', label: 'Australian Capital Territory', className: 'State-ACT' },
    { value: 'new-south-wales', label: 'New South Wales', className: 'State-NSW' },
    { value: 'victoria', label: 'Victoria', className: 'State-Vic' },
    { value: 'queensland', label: 'Queensland', className: 'State-Qld' },
    { value: 'western-australia', label: 'Western Australia', className: 'State-WA' },
    { value: 'south-australia', label: 'South Australia', className: 'State-SA' },
    { value: 'tasmania', label: 'Tasmania', className: 'State-Tas' },
    { value: 'northern-territory', label: 'Northern Territory', className: 'State-NT' },
  ];

  var JumpToDatabaseWidget = React.createClass({

    render: function () {
      var options = STATES;
      return (
        <div>
          <Select
            ref="stateSelect"
            disabled={false}
            options={options} />
        </div>
      );
    }
  });

Here is a screenshot with the stacktraces:

bildschirmfoto 2016-01-28 um 15 43 13

Do you have an idea what I am doing wrong?

robertkowalski avatar Jan 28 '16 14:01 robertkowalski

react-select is now controlled, so pass value and an onChange handler.

bruderstein avatar Jan 29 '16 15:01 bruderstein

Weird error though... if that's it, we should improve that :)

bruderstein avatar Jan 29 '16 15:01 bruderstein

hm didn't help:

          <Select
            onChange={function () {}}
            value="blerg"
            ref="stateSelect"
            disabled={false}
            options={options} />

robertkowalski avatar Jan 29 '16 15:01 robertkowalski

branch is at https://github.com/robertkowalski/couchdb-fauxton/tree/react-select

robertkowalski avatar Jan 29 '16 15:01 robertkowalski

I smell a require.js / react-select interop issue... I'll take clone it and take a look - probably not till early next week though :(

bruderstein avatar Jan 29 '16 17:01 bruderstein

my awesome coworker @garrensmith found out that the 'react-input-autosize is not loaded properly with AMD - we'll keep you updated!

robertkowalski avatar Feb 03 '16 11:02 robertkowalski

I put

<script src="https://localhost:8000/js/react-input-autosize.js"></script> 

and it helps

ButuzGOL avatar Feb 23 '16 13:02 ButuzGOL

I have the same issue

<Select.Async name="form-field-name" value="one" loadOptions={getOptions} />

Gives me:

Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

mharrisweb avatar Apr 01 '16 11:04 mharrisweb

we switched to webpack and it solved our issue

robertkowalski avatar Apr 01 '16 14:04 robertkowalski

Thanks for the update @robertkowalski - I'll see what I can do to test this for the next build and update the instructions for AMD usage... we could probably detect that react-input-autosize is not loading correctly and warn on that, which would at least make this problem an easier one to debug.

JedWatson avatar Apr 01 '16 15:04 JedWatson

I'm also getting the same error as @mharrisweb

It seems that instead of using <Select.Async loadOptions={} /> the approach that works is <Select asyncOptions={} /> but that doesn't seem to be in the documented options here although there are references to it.

sh3r4rd avatar May 05 '16 16:05 sh3r4rd

+1 @skbailey I had exactly the same problem, using asyncOptions fixed it. I use version ^0.9.1 - maybe something changed?

sebbsan avatar May 06 '16 14:05 sebbsan

Not sure if this is going to help anyone, but I was using import { Select } from 'react-select' instead of var Select = require('react-select'). Once I changed it to var Select = require('react-select'), it worked.

anton6 avatar May 10 '16 21:05 anton6

Seems to be related to #270

jochenberger avatar May 11 '16 13:05 jochenberger

@anton6 Alternatively use:import Select from 'react-select'. (it's the default export, so no braces required)

koebeen avatar May 15 '16 10:05 koebeen

Thanks @skbailey! Using asyncOptions fixed this strange behaviour.

dalpo avatar Sep 11 '16 10:09 dalpo

I'm getting Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. in version 1.0.0-rc.1

import Select from 'react-select';

<Select.Async {...this.props}
        ref='selectField'
        value={this.getSavedValue()}
        loadOptions={this.getItems.bind(this)}/>

I don't want to use asynOptions as this would mean down grading. Has there been a fix put in place for this?

Cein-Markey avatar Sep 19 '16 14:09 Cein-Markey

Hey guys,

I am currently going threw an upgrade of a few modules.

I am getting the same error as above

Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object. You likely forgot to export your component from the file it's defined in. Check the render method of `DestinationInputField`.

I import it like this ->

import Select from 'react-select';

My component looks like this ->

<div id="destination-input">
                <FormFieldWrapper label="Destination"
                                  help={errorMessage}>
                <Select
                        id="destination-input"
                         name="destination"
                        onChange={this.destinationSelected.bind(this)}
                        options={destinationOptions}
                        multi={true}
                        value={selectedDestinationId}
                        placeholder="All Destinations"
                    />
                </FormFieldWrapper>
            </div>

I am on version 1.0.0-rc.3 with the latest version of react 15.4.2 and react-dom 15.4.2

Any help would be great.

PhilKearney avatar Feb 21 '17 13:02 PhilKearney

Same issue as those above: type is invalid -- expected a string(for built-in components)...

All that's required to throw the error is

import Select from react-select

<Select />

David-OConnor avatar May 10 '17 08:05 David-OConnor

Having the same issue. webpack/es2015

aramosipyan avatar May 30 '17 15:05 aramosipyan