首页 > 解决方案 > 如何在许多 const react 中存储和导出对象数量

问题描述

我是 React 的新手,在每个组件中我都初始化了我渲染组件的对象

在所有组件对象都被初始化后,我想将所有的整个对象存储在一个文件中。如何存储和导出具有不同变量的所有对象

这是我的示例代码

import React, { Component } from 'react';
import { Link } from 'react-router-dom';

class Footer extends Component {
    render() {
        const links = {
            classname: ["fa-phone", "fa-envelope","fa-location-arrow"],
            content: ["Tel:", "Email:","Location:"],
        };
        return (
             <div>
                  <ul>    
                 {links.classname.map((name, i) =>
                    <li style={{ listStyleType:"none" }} key={name}> <i className={`fa ${name} text-primary`}></i> <b className="p-lr5">{links.content[i]}</b>{links.subcontent[i]}</li>
                     )}
                  </ul>
             </div>    
         );
    }
}    
 export default Footer;

我尝试这样做如何将对象集合保存在一个文件中

const links1 =  {
    classname: ["fa-phone", "fa-envelope", "fa-location-arrow"],
    content: ["Tel:", "Email:", "Location:"],
    subcontent: ["04324-263537", "karurknv@gmail.com", "239, Jawahar Bazaar, karur - 639001"],
};
const links2 =  {
    links: ["Home", "About Us", "Products", "Gallery", "Services"],
    to: ["/", "aboutus", "/products", "/gallery", "/services", "/contact"],
};
const links3 =  {
    links2: ["/terms&condition", "/privatepolicy", "/contact"],
    to2: ["Terms & Condition", "Privacy Policy", "Contact Us"]
};

请帮我

标签: arraysreactjsreact-redux

解决方案


使用export而不是export default. 喜欢export const MyComponent


推荐阅读