App.js 中的函数未显示在 .jsx 文件中
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是导出函数的方式,但是如果您想要 React 组件,那么您的组件应该以大写字符开头。
This is how you export functions, but if you want React components then your component should start with a capital character.