App.js 中的函数未显示在 .jsx 文件中

发布于 2025-01-18 10:59:42 字数 976 浏览 0 评论 0原文

我有一个 React 网站,并且有一个 jsx 文件,该文件试图调用我在 App.js 中定义的一些函数,

import React from "react";
import function1 from './App.js'
import function2 from './App.js'
import function3 from './App.js'

function Home() {
  return (
    <div className="home">
      <div class="container">
        <div>
          {function1() ? function2(): function3()}
        </div>
      </div>
    </div>
  );
}

export default Home;

然后我有一个如下所示的 App.js 文件:

import React from 'react';
import './App.css'

function App() {
    const function1 = () => { 
        return booleanvalue
    }
    const function2 = () => { 
        return (<button onClick={...} ... </button>)
    }
    const function3 = () => { 
        return (<button onClick={...} ... </button>)
    }
}

export default App;

但 jsx 文件中没有显示任何内容。我尝试在最后导出这些函数,但这也没有做任何事情。有什么方法可以在我的 App() 中导出这些本地函数或调用它们,因为我已经导出了 App?

I have a react website and have a jsx file that is trying to call some functions I defined in my App.js

import React from "react";
import function1 from './App.js'
import function2 from './App.js'
import function3 from './App.js'

function Home() {
  return (
    <div className="home">
      <div class="container">
        <div>
          {function1() ? function2(): function3()}
        </div>
      </div>
    </div>
  );
}

export default Home;

I then have an App.js file that looks like this:

import React from 'react';
import './App.css'

function App() {
    const function1 = () => { 
        return booleanvalue
    }
    const function2 = () => { 
        return (<button onClick={...} ... </button>)
    }
    const function3 = () => { 
        return (<button onClick={...} ... </button>)
    }
}

export default App;

But nothing shows up from the jsx file. I tried exporting these functions at the end but this also doesn't do anything. Is there any way I can export these local functions within my App() or call them because I am already exporting App?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

献世佛 2025-01-25 10:59:42
import './App.css'
    export const function1 = () => { 
        return booleanvalue
    }

export const function2 = () => { 
        return (<button onClick={...} ... </button>)
    }

    export const function3 = () => { 
        return (<button onClick={...} ... </button>)
    }

export function App() {



}

export {App, function, function2, function3 }

这就是导出函数的方式,但是如果您想要 React 组件,那么您的组件应该以大写字符开头。

import './App.css'
    export const function1 = () => { 
        return booleanvalue
    }

export const function2 = () => { 
        return (<button onClick={...} ... </button>)
    }

    export const function3 = () => { 
        return (<button onClick={...} ... </button>)
    }

export function App() {



}

export {App, function, function2, function3 }

This is how you export functions, but if you want React components then your component should start with a capital character.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文