簡體   English   中英

在Meteor + React中,如何在父React組件中渲染子React組件?

[英]in Meteor+React, how can i render a child React component in a parent React component?

我已經定義了父組件和子組件。 關聯他們時出現錯誤。

Parent.jsx

import React, {Component, PropTypes} from 'react';
import {Child} from '/imports/ui/components/Child';

export default class Parent extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <Child />
        );
    }
}

Child.jsx

import React, {Component, PropTypes} from 'react';

export default class Child extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return (
            <div>child</div>
        );
    }
}

我已經向Blaze注冊了父母:

Template.registerHelper("Parent", function() {
    return Parent;
});

...而且我正在像這樣使用它:

<div>
    {{> React component=Parent }}
</div>

我在瀏覽器控制台中收到此錯誤:

警告:React.createElement:type不能為null,undefined,boolean或number。 它應該是一個字符串(對於DOM元素)或一個ReactClass(對於復合組件)。 檢查Parent的渲染方法。

我確實有其他React組件在該項目中工作,但是它們都沒有這種簡單的父子關系。 我究竟做錯了什么?

你應該

export Child而不是export default Child

要么

import Child而不是import {Child}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM