【问题标题】:Invalid type when trying to render component尝试渲染组件时类型无效
【发布时间】:2021-07-06 16:11:55
【问题描述】:

我尝试在我的 Meteor React 应用中使用 FlowRouter 和 react-mounter,但收到以下错误消息:

警告:React.createElement:类型无效——需要一个字符串 (对于内置组件)或类/函数(对于复合 组件)但得到:对象。

client/main.html 在正文中有这个 div:

<div id="root"></div>

client/main.jsx:

import React from "react";
import { Meteor } from "meteor/meteor";
import { render } from "react-dom";
import { App } from "/imports/ui/App";
import "/client/router";

Meteor.startup(() => {
  render(<App/>, document.getElementById("root"));
});

client/router.jsx 有这条路线:

import React from "react";
import { FlowRouter } from "meteor/ostrio:flow-router-extra";
import { mount, withOptions } from "react-mounter";

import App from "/imports/ui/App";
import Start from "/imports/ui/Start";

const mount2 = withOptions({
  rootId: "root"
}, mount);

FlowRouter.route("/", {
  name: "Start",
  action() {
    console.log("start");
    mount2(App, {
      content: <Start />
    });
  }
});

imports/ui/App.jsx:

import React from "react";

export const App = ({content}) => {
  console.log("content", content);
  return <div>{content}</div>
};

内容打印undefined

以及我要渲染的imports/ui/Start.jsx 组件:

import React from "react";

export const Start = () => (
  <div>
    start
  </div>
);

我错过了什么?

【问题讨论】:

    标签: reactjs meteor flow-router


    【解决方案1】:

    我的问题是/client/router.jsx 中的导入应该有大括号,例如:

    import { App } from "/imports/ui/App";
    import { Start } from "/imports/ui/Start";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      • 2016-05-15
      • 2020-12-02
      • 1970-01-01
      相关资源
      最近更新 更多