谷歌克隆 Part15 30 创建搜索结果组件3/3 引入 react-parser 以反映 API 响应的 HTML
简而言之。
目录
开发环境
操作系统:Windows10
集成开发环境:VSCode
“@next/font”: “13.1.5”,
“autoprefixer”: “10.4.14”,
“eslint”: “8.39.0”,
“eslint-config-next”: “13.3.1”,
“next”: “13.3.1”,
“postcss”: “8.4.23”,
“react”: “18.2.0”,
“react-dom”: “18.2.0”,
“react-icons”: “^4.8.0”,
“tailwindcss”: “3.3.2”
“@next/font”:”13.1.5″,
“autoprefixer”:”10.4.14″,
“eslint”:”8.39.0″,
“eslint-config-next”:”13.3.1″,
“next”:”13.3.1″,
“postcss”:”8.4.23″,
“react”:”18.2.0″,
“react-dom”:”18.2.0″,
“react-icons”:”^4.8.0″,
“tailwindcss”:”3.3.2”
实施的要点
请用中国语言原生地转述以下代码部分
将以下内容以中文进行本地化翻译,只需一种选项:
软件包
{
"name": "googlecone12",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"autoprefixer": "10.4.14",
"eslint": "8.39.0",
"eslint-config-next": "13.3.2",
"next": "13.3.2",
"postcss": "8.4.23",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2",
"react-icons": "^4.7.1",
+ "html-react-parser": "^3.0.9"
}
}
网络搜索结果
import Link from "next/link";
import Parser from "html-react-parser";
export default function WebSearchResults({results}){
return(
<div className="w-full mx-auto px-3 pb-24 sm:pl-[5%] md:pl-[14%] lg:pl-52">
<p className="text-gray-600 text-sm mb-5 mt-3">
About {results.searchInformation?.formattedTotalResults}
results ({results.searchInformation?.formattedSearchTime} seconds)
</p>
{results.items?.map((result) => (
<div className="mb-8 max-w-xl" key={result.link}>
<div className="group flex flex-col">
<Link className="text-sm truncate" href={result.link}>
{result.formattedUrl}
</Link>
<Link className="group-hover:underline decoration-blue-800 text-xl truncate font-medium text-blue-900" href={result.link}>
{result.title}
</Link>
<p className="text-gray-600">
+ {Parser(result.htmlSnippet)}
</p>
</div>
</div>
))}
</div>
)
}
请首先查看以下资料,以获取更多相关信息及参考。
其他
反应分析器
优达学城
GitHub提交记录