简体   繁体   English

如何从 React JS 中的另一个组件导入多个变量或列表?

[英]How to import mulitple variables or list from another component in React JS?

I have a Profile.js component which uses some list.我有一个 Profile.js 组件,它使用了一些列表。 The list is two big so I want to shift the list to a different LabelValue.js component and import it in Profile.js.该列表很大,因此我想将列表转移到不同的 LabelValue.js 组件并将其导入 Profile.js。 But I'm not able to do so.但我不能这样做。 Kindly depict the right way to do the import and export.请描述正确的进出口方式。

In LabelValue.js在 LabelValue.js 中

const bloodGroups = [
  { label: "Choose", value: "" },
  { label: "A+", value: "A+" },
  { label: "B+", value: "B+" },
  { label: "AB+", value: "AB+" },
  { label: "O+", value: "O+" },
  { label: "O-", value: "O-" },
  { label: "A-", value: "A-" },
  { label: "B-", value: "B-" },
  { label: "AB-", value: "AB-" },
];

 const genders = [
    { label: "Choose", value: "" },
    { label: "Male", value: "Male" },
    { label: "Female", value: "Female" },
    { label: "Others", value: "Others" },
  ];

export default { genders, bloodGroups };

In Profile.js在 Profile.js 中

import { bloodGroups, genders } from ".path/to/LabelValue.js"

The Error错误

./src/Pages/Profile.js
Attempted import error: 'bloodGroups' is not exported from '../LabelValue'.

Use利用

export { genders, bloodGrousps };

NOT不是

export default { genders, bloodGrousps };

Default is for single value默认为单个值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将组件导入另一个组件中,其中包括反应 js 中的图像 - How to import the component in another component which include image in react js 如何将带有状态变量的jsx导入另一个React组件? - How to import jsx with state variables into another react component? 如何从 React JS 中的另一个组件更改同级组件的事件 - How to change sibling component on event from another component in React JS 如何将参数从一个 React 组件导入到另一个组件 - How to import parameters from one React component to another 如何将变量从一个组件导入另一个? 反应 - How can I import a variable from a component to another ? React 如何从另一个文件“ .txt,.js”导入“ var”变量? - How to import “var” variables from another file “.txt, .js”? React JS 从另一个组件渲染组件 - React JS render component from another component Babel - 从 JS 文件导入 function 并在另一个 JS 文件的 React 组件中使用它 - Babel - Import a function from a JS file and use it in a React component in another JS file 从另一个文件夹问题中反应导入组件 - React import component from another folder issue 如何将javascript从组件导入另一个组件? - How to import javascript from component to another component?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM