如何修复元素类型无效:预期使用字符串(对于内置组件)或类/函数(对于复合组件),但得到:对象

时间:2018-10-29 15:37:17

标签: reactjs react-select react-rails

我正在尝试运行ReactRails应用程序,并试图运行一个非常简单的react-select组件。但是,在同一文件中,如果我仅打印一个简单的2018-10-29 10:53:52.204 7840-8080/murray.ann.myapplication E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: murray.ann.myapplication, PID: 7840 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:353) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:944) at java.util.Currency.getInstance(Currency.java:91) at murray.ann.myapplication.CurrencyHelper.getUserCurrency(CurrencyHelper.java:191) at murray.ann.myapplication.SelectCurrencyAdapter.getSelectedCurrencyPosition(SelectCurrencyAdapter.java:106) at murray.ann.myapplication.SelectCurrencyFragment$1.doInBackground(SelectCurrencyFragment.java:82) at murray.ann.myapplication.SelectCurrencyFragment$1.doInBackground(SelectCurrencyFragment.java:76) at android.os.AsyncTask$2.call(AsyncTask.java:333) 元素,则它可以工作,但是h2不起作用。它给出:

<Select/>

我正在尝试使用Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. 组件。我已经通过react-select命令安装了它。

User.jsx:

yarn add

我对React世界很陌生。我在这里想念什么?我在做什么错了?

注意:这不能解决我的问题:Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object

1 个答案:

答案 0 :(得分:2)

我不确定module.exports如何与React一起玩。当我尝试使用ES6语法编写代码时,它似乎可以正常工作。

import React from 'react';
import Select from 'react-select';

,然后使用ES6导出而不是module.exports:

export default User;

选择组件似乎不是问题。