簡體   English   中英

如何在反應中添加指向字符串的鏈接

[英]How to add link to a string in react

我正在嘗試在組件的字符串中添加鏈接,但我遇到了問題,它顯示為 Object Object。

我將 productPage 鏈接添加為 object 或作為我的工具提示組件的組件。

在這種情況下我該如何實現?

這是我的代碼庫:

工具提示.js:

const useStylesBootstrap = makeStyles({
  arrow: {
    color: "#e06a56"
  },
  tooltip: {
    backgroundColor: "#e06a56",
    fontSize: 11,
    width: '180px'
  }
});

function BootstrapTooltip(props) {
  const classes = useStylesBootstrap();

  return <Tooltip arrow classes={classes} {...props} />;
}

export default function CustomizedTooltips(props) {
  return (
    <BootstrapTooltip title={props.content}>{props.button}</BootstrapTooltip>
  );
}

應用程序.js:

const renderHideOptionalClauseTrigger = () => {

  const productPage = () => {
    return (
      <Link to="/product">
        Product page
      </Link>
    )
  }

  return (
    <div>
      <text>My Optional Loan Clause</text>
      <Tooltip
        button={
          <span>
            <i className="fas fa-exclamation-circle"></i>
          </span>
        }
        content={
          `Will be added verbatim as last clause to the loan agreement. See ${productPage} for other clauses.`
        }
      />
    </div>
  );
};

更新! 如果我這樣放置我的鏈接

const productPage = <Link className="orange-link" to="/product">Product page</Link>

它會來 Object Object..

在此處輸入圖像描述

您可能需要使用 JSX 元素——否則它會將您的鏈接轉換為字符串(並顯示 [object Object]):

content={
      <>Will be added verbatim as last clause to the loan agreement. See {productPage} for other clauses.</>
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM