简体   繁体   English

React - 如何将变量从一个文件获取到另一个文件

[英]React - how to get variable from one file to another

The due date to my project is today and I can not fix this problem.我的项目的截止日期是今天,我无法解决这个问题。 This is my first react project so everything is still new to me.这是我的第一个 react 项目,所以对我来说一切都是新的。

I have a file called "fullcalendar" with an export function which renders a calendar.我有一个名为“fullcalendar”的文件,它具有一个呈现日历的导出功能。 Now I have an attribute from this calendar that I want to export into another file "popupwindow" as the info that I am getting from the calendar is needed for the popup window.现在我有一个来自这个日历的属性,我想将它导出到另一个文件“popupwindow”中,因为弹出窗口需要我从日历中获取的信息。 How can I export a variable if I am already exporting the main function in that file "fullcalendar" without using Child and Parent.如果我已经在该文件“fullcalendar”中导出主函数而不使用子级和父级,如何导出变量。

I can also add some code for further information我还可以添加一些代码以获取更多信息

You can use default export to export your function and named export to export other values.您可以使用默认导出来导出您的函数,并使用命名导出来导出其他值。

Default export:默认导出:

function foo(){}
export default foo

// usage in another file:
import foo from './foo.js'

Named export:命名导出:

const value = 25
export value
// usage in another file:
export {value} from './foo.js'

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

相关问题 如何在反应中将函数变量从一个文件传递到另一个文件 - how to pass function variable from one file to another in react 在反应中将变量从一个文件导出到另一个文件 - Export variable from one file to another in react React JS:如何将变量从一个文件传递到另一个文件,该文件不是同一文件的父文件或子文件? - React JS: How to pass variable from one file to another file, which is not parent or child of the same? 在 React Native 中将变量从一个文件传递到另一个文件 - Pass a variable from one file to another in React Native React 如何从另一个文件中获取数据 - How to get data from another file in React 如何从另一个组件获取组件变量,但它们都在同一个文件中 React - how to get a Component variable from another component but their both in the same file React 如何在React中将变量从一种方法传递给另一种方法 - How to pass a variable from one method to another in React 如何将变量从一个组件转移到另一个组件 - how to transfer a variable from one component to another react 如何将 const 变量从一个组件传递到另一个组件 - How to pass a const variable from one component to another react 如何将一个变量从一个反应组件使用到另一个组件 - How to use a variable from a react component to another one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM