首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在页脚设置中添加唯一键?

如何在页脚设置中添加唯一键?
EN

Stack Overflow用户
提问于 2020-07-15 20:26:17
回答 2查看 36关注 0票数 0

这是我的footer.tsx。

我无法在以下组件中设置唯一密钥。

我如何才能以不同的方式简化这个页脚?

代码语言:javascript
复制
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>
  );
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-07-15 23:02:05

使用以下代码:

代码语言:javascript
复制
{footerLinks.footer2.map((link) => (
            <li key={link}>
      ....
票数 1
EN

Stack Overflow用户

发布于 2020-07-15 21:10:03

map方法接受一个可选的参数index,它是数组中正在处理的当前元素的索引。您可以像这样在map方法中传递它。

代码语言:javascript
复制
 {footerLinks.footer1.map((link, index) => (
     <li>
       <Link
         to={{
           pathname: "/",
             }}
           key={index}
         >
        {link}
      </Link>
      </li>
   ))}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62914804

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档