reactjs - 如何在页脚设置中添加唯一键?
问题描述
这是我的footer.tsx。
我无法在以下组件中设置唯一键。
如何以不同的方式简化此页脚?
import React from "react";
import {
Container,
Row,
Col,
InputGroup,
FormControl,
Button,
} from "react-bootstrap";
import "./footer.scss";
import { Link } from "react-router-dom";
type footerLinks = {
[x: string]: string[];
};
const footerLinks = {
footer1: [
"Browse Experts",
"Emergency",
"Services",
"Name My Price",
"Recurring Services",
"Service Packages",
"Gurantees & Terms of use",
],
footer2: [
"Log in",
"Join Our Network",
"Resource Center",
"Contractor Leads",
"Terms & Conditions",
],
footer3: [
"Contact Us/Customer Care",
"How it works",
"FAQs",
"Screening Process",
"About the company",
],
footer4: [
"Handyman",
"Cleaning",
"Removalists",
"Gardening",
"Automotive",
"All Sesrvices",
],
};
export default function Footer() {
return (
<footer className="dark-bg pt-7">
<Container className="pb-5">
<Row>
{/* Footer 1 Start */}
<Col lg={2} sm={6}>
<h6 className="footer-title">Service Seekers</h6>
<ul className="footer-links">
{footerLinks.footer1.map((link) => (
<li>
<Link
to={{
pathname: "/",
}}
>
{link}
</Link>
</li>
))}
</ul>
</Col>
{/* Footer 1 End */}
{/* Footer 2 Start */}
<Col lg={2} sm={6}>
<h6 className="footer-title">For Service Expert</h6>
<ul className="footer-links">
{footerLinks.footer2.map((link) => (
<li>
<Link
to={{
pathname: "/",
}}
>
{link}
</Link>
</li>
))}
</ul>
</Col>
{/* Footer 2 End */}
{/* Footer 3 Start */}
<Col lg={2} sm={6}>
<h6 className="footer-title">About Expertibly</h6>
<ul className="footer-links">
{footerLinks.footer3.map((link) => (
<li>
<Link
to={{
pathname: "/",
}}
>
{link}
</Link>
</li>
))}
</ul>
</Col>
{/* Footer 3 End */}
{/* Footer 4 Start */}
<Col lg={2} sm={6}>
<h6 className="footer-title">Popular Services</h6>
<ul className="footer-links">
{footerLinks.footer4.map((link) => (
<li>
<Link
to={{
pathname: "/",
}}
>
{link}
</Link>
</li>
))}
</ul>
</Col>
{/* Footer 4 End */}
{/* Footer 5 Start */}
<Col lg={4}>
<h6 className="footer-title">Join Our Newsletter</h6>
<div className="pt-3">
<InputGroup className="mb-3">
<FormControl
placeholder="Your Email Address"
aria-label="Your Email Address"
aria-describedby="basic-addon2"
className="rounded-0 border-0"
/>
<InputGroup.Append>
<Button className="rounded-0 border border-primary">
Join Expertibly
</Button>
</InputGroup.Append>
</InputGroup>
</div>
</Col>
{/* Footer 5 End */}
</Row>
</Container>
<div className="py-3 text-white text-center footer-caption">
@2020 EXPERTIBLY. All Right Reserved
</div>
<div className="footer-chat-icon"></div>
</footer>
);
}
解决方案
map 方法接受一个可选参数 index,它是数组中正在处理的当前元素的索引。你可以像这样在你的地图方法中传递它。
{footerLinks.footer1.map((link, index) => (
<li>
<Link
to={{
pathname: "/",
}}
key={index}
>
{link}
</Link>
</li>
))}
推荐阅读
- ssh - GCE 中的运行在某个固定点崩溃
- javascript - 如何检测浏览器的完整版本?
- spring-batch - 使用非 FlatFileItemReader 的 Spting Batch MultiResourceItemReader
- knockout.js - 无法在淘汰赛中使用 getJSON 方法获取 JSON 数据
- python - Python - 如果没有从客户端发送的数据,如何停止套接字 recv() 等待
- css - 如果 Angular Material 按钮内的文本长于按钮的宽度,如何断词?
- sql - SQL 查询未产生预期结果
- wpf - TargetNullValue 在 WPF 和 Xamarin.Forms 中的工作方式是否相同?
- ios - 当我将元素附加到全局数组时,它被先前的元素替换(奇怪的行为)?
- r - R中同一行的条件累积和