Javascript React:使用React weather时元素类型无效
我弄糊涂了。具有自写组件,通过npm安装,如下所示:Javascript React:使用React weather时元素类型无效,javascript,reactjs,npm,Javascript,Reactjs,Npm,我弄糊涂了。具有自写组件,通过npm安装,如下所示: import React, { Component } from 'react'; import './App.css'; import Weather from './components/Weather'; class App extends Component { componentWillMount() { } render() { return (
import React, { Component } from 'react';
import './App.css';
import Weather from './components/Weather';
class App extends Component {
componentWillMount() {
}
render() {
return (
<div className="App">
<Weather />
</div>
);
}
}
export default App;
src/components文件夹中的My Weather.js组件
导致以下错误:
元素类型无效:内置组件应为字符串,复合组件应为类/函数,但Get:未定义。您可能忘记了从定义组件的文件中导出组件,或者您可能混淆了默认导入和命名导入。检查“天气”的渲染方法
我想知道,因为进出口对我来说还行,所以我试着改变天气,简单地说:
<div>
<p>hello world</p>
</div>
瞧,错误消失了
所以,在这一点上,我很好奇,我怎样才能让天气对工作做出反应 检查react weather的最新版本,如果您导入它,您会发现只有两个命名导出可用:YahooWeather和AccuWeather 文件似乎已经过时了 编辑: 我克隆了repo并创建了一个新的构建,它确实可以按照文档中的说明工作。 如果要使用它,您需要执行以下操作:
git clone https://github.com/AmarShaked/ReactWeather
yarn install (inside root folder of the cloned repo)
yarn build (to fire the webpack new build)
因此,在[repo_root]/lib/index.js中,您将拥有uglified包。您可以复制到正在使用的项目,然后在代码中引用如下内容
import { GenericWeather } from '../[relative_path_to_script]/index';
谢谢你能告诉我你在哪里找到它的存储库吗?这里有:。我正在看一看,如果我可以修复它,使公关,因为它似乎是一个坏的建设。源代码是根据文档编写的,但是webpack构建不是。但是这里的两个组件是用GenericWeather和OpenWeatherMap命名的。对吗?工作!谢谢你弄明白了!
import { GenericWeather } from '../[relative_path_to_script]/index';