Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 我可以在React中使字符串可点击吗?_Reactjs_Material Ui - Fatal编程技术网

Reactjs 我可以在React中使字符串可点击吗?

Reactjs 我可以在React中使字符串可点击吗?,reactjs,material-ui,Reactjs,Material Ui,我使用material ui和react显示了一些字符串s: <Typography paragraph variant="body1"> {text1} <strong>{text2}</strong> </Typography> {text1} {text2} 它们由数据库查找填充。如果数据库条目中有URL,如何使此文本可单击(例如数据库中的文本为:“microsoft:www.

我使用material ui和react显示了一些
字符串
s:

    <Typography paragraph variant="body1">
      {text1}
      <strong>{text2}</strong>
    </Typography>

{text1}
{text2}

它们由数据库查找填充。如果数据库条目中有URL,如何使此文本可单击(例如数据库中的文本为:“microsoft:www.microsoft.com”?

您可以使用Material UI的
链接
组件:


{text1}
{text2}

不幸的是,
String
本质上没有处理单击事件的能力,它必须是
HTML
标记,只有这样才能触发单击事件。因此,您可以将此字符串添加到其他标记中,并在该标记上提供单击事件,或者委派事件并检查单击元素,以便执行rm it上的一个函数hanks没有神奇的方法使
字符串
可点击?代码不是神奇的。使文本可点击的唯一方法是将其包含在一个组件中,在本例中为
链接
。鉴于并非所有的DB条目都有URL,最好使用正则表达式确定URL是否存在并提取它,然后使用条件格式插入
链接
组件。但我认为这完全证明了另一个问题。
<Typography paragraph variant="body1">
  <Link href={url}>
    {text1}
  </Link>
  <strong>{text2}</strong>
</Typography>