如何使React Native中可重复使用的代码?
如何创建可重复使用的“函数”:
const Customer = (name, ID) => {
<Text style={{ fontSize: 12 }}>{name}</Text>
<Text style={{ fontSize: 10 }}>{ID}</Text>}
这样我可以轻松地将客户插入以下功能。
function Shop() {
return (
<DraxProvider>
<DraxView>
<Customer name="A" ID="1">
</DraxView>
<DraxView>
<Customer name="B" ID="2">
</DraxView>
<DraxView>
<Customer name="C" ID="3">
</DraxView>
</DraxProvider>
)}
blockquote
How can I create reusable "functions" like this:
const Customer = (name, ID) => {
<Text style={{ fontSize: 12 }}>{name}</Text>
<Text style={{ fontSize: 10 }}>{ID}</Text>}
So that I can insert customers into the following function easily.
function Shop() {
return (
<DraxProvider>
<DraxView>
<Customer name="A" ID="1">
</DraxView>
<DraxView>
<Customer name="B" ID="2">
</DraxView>
<DraxView>
<Customer name="C" ID="3">
</DraxView>
</DraxProvider>
)}
Blockquote
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该首先尝试将您的
customer
作为一个类似的组件,请注意以下注意:
(
符号,而不是{
{props
将参数传递到&lt;&lt;&lt;/&gt;/&gt;
akafragments
的组件用法文本
组件您应该能够按照预期重复使用
You should first try to make your
Customer
as a component like belowNote the following:
(
sign as opposed to{
props
to pass parameter to component<></>
akaFragments
since you have twoText
componentWith that you should be able to reuse as you intended