使用相同的反应成分15次

时间:2018-08-29 14:39:27

标签: javascript reactjs ecmascript-6 export components

我有一个组件,它将根据props id检查type属性,以便决定要呈现的内容。

“类型”来自嵌入到.njk文件中的JSON数据,反应组件已安装到该文件中。

数据外观示例:

[
    {
        type: 'a',
        data: [example arr]
    },
    {
        type: 'b',
        data: [example arr]
    },
    {
        type: 'a',
        data: [example arr]
    },
    {
        type: 'b',
        data: [example arr]
    },
]

我的组件将渲染为A,B或NULL。 (例如,缘故)

var components = [
    {
        id: 'one',
        component: component,
        props: {
            compId: 1
        },
    },
    {
        id: 'two',
        component: component,
        props: {
            compId: 2
        },
    },
    //ect.... repeated
]

组件

render(){
    if(type == 'a'){
        return (
            <div>
                A
            </div>
        );
    } else if (type == 'b'){
        return (
            <div>
                B
            </div>
        );
    } else {
        return null;
    }
}

但是,我在多次渲染组件时遇到问题。我假设它与我的导出方式有关?

例如

export default component;

我是否缺少像“新”这样的明显东西?

0 个答案:

没有答案