gpt4 book ai didi

javascript - 是否可以从 React 函数中导出一个常量变量?

转载 作者:行者123 更新时间:2023-11-29 22:48:07 26 4
gpt4 key购买 nike

我正在尝试使用 API 调用设置对象的值,并将结果从我的应用程序内部导出到其他类。

这就是我想做的事情

import {MaterialUIComponentsNavigation} from 'app/main/documentation/material-ui-components/MaterialUIComponentsNavigation';
import {authRoles} from 'app/auth';
import {callTextApi} from "../services/textService/textContext";
import {useState} from "react";

function navigationConfig () {

console.log("Random");
return test = [
{
'id' : 'applications',
'title' : 'Applications',
'type' : 'group',
'icon' : 'apps',
'children': [
{
'id' : 'dashboards',
'title' : 'Dashboards',
'type' : 'collapse',
'icon' : 'dashboard',
'children': [
{
'id' : 'analytics-dashboard',
'title': 'Raaaaaaaaaaaa',
'type' : 'item',
'url' : '/apps/dashboards/analytics'
},
{
'id' : 'project-dashboard',
'title': 'Project',
'type' : 'item',
'url' : '/apps/dashboards/project'
}
]
},
//some more object fields
}
export default navigationConfig;

我的问题是:有没有办法只导出测试变量而不导出整个函数?我需要这是一个函数,因为我不能在常量内使用 react Hook ,这就是为什么我试图从函数内部导出常量。

导出看起来像这样

navigationConfig() {
console.log("Random");
return test = [{
'id': 'applications',
'title': 'Applications',
'type': 'group',
'icon': 'apps',
'children': [{
'id': 'dashbo…

什么时候应该是这样的:

(10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id: "authentication", title: "Authentication", type: "collapse", icon: "lock", badge: {…}, …}
1: {id: "coming-soon", title: "Coming Soon", type: "item", icon: "alarm", url: "/pages/coming-soon"}
2: {id: "errors", title: "Errors", type: "collapse", icon: "error", children: Array(2)}
3: {id: "invoice", title: "Invoice", type: "collapse", icon: "receipt", children: Array(2)}
4: {id: "maintenance", title: "Maintenance", type: "item", icon: "build", url: "/pages/maintenance"}
5: {id: "pricing", title: "Pricing", type: "collapse", icon: "attach_money", children: Array(3)}
6: {id: "profile", title: "Profile", type: "item", icon: "person", url: "/pages/profile"}
7: {id: "search", title: "Search", type: "collapse", icon: "search", children: Array(2)}
8: {id: "faq", title: "Faq", type: "item", icon: "help", url: "/pages/faq"}
9: {id: "knowledge-base", title: "Knowledge Base", type: "item", icon: "import_contacts", url: "/pages/knowledge-base"}

希望这个问题有意义。

附言我还在学习 React,所以请不要太苛刻 :D

最佳答案

您可以像这样导出一个变量:

const data = {};

export default data;

关于javascript - 是否可以从 React 函数中导出一个常量变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57953194/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com