[英]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.