{"id":38153,"date":"2023-03-29T04:36:16","date_gmt":"2024-02-15T21:29:50","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/"},"modified":"2024-04-29T20:57:22","modified_gmt":"2024-04-29T12:57:22","slug":"%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/","title":{"rendered":"\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider"},"content":{"rendered":"<h2>\u76ee\u5f55<\/h2>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5f00\u53d1\u73af\u5883<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4e3a\u4ec0\u4e48\u60f3\u8981\u5199\u8fd9\u7bc7\u6587\u7ae0<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u9996\u5148\uff0c\u5728npm\u4e2d\u6267\u884cstyled-components\u7684\u5b89\u88c5\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728src\u76ee\u5f55\u4e0b\u521b\u5efatheme\u76ee\u5f55\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>theme.ts\u7684\u793a\u4f8b\u4ee3\u7801\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u7f16\u8f91index.tsx\u6587\u4ef6\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5c1d\u8bd5\u5c06\u4ee3\u7801\u5b9e\u9645\u5199\u5165\u7ec4\u4ef6\u4e2d\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8c03\u7528\u5e76\u67e5\u770b\u521b\u5efa\u7684\u6309\u94ae\u7ec4\u4ef6\u7684\u7ed3\u679c\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u611f\u60f3<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u8865\u5145\u8bf4\u660e<\/ol>\n<h2>\u5f00\u53d1\u73af\u5883<\/h2>\n<p>&#8220;react&#8221;: &#8220;^18.2.0&#8221;,<br \/>\n&#8220;typescript&#8221;: &#8220;^4.9.5&#8221;<\/p>\n<p>&#8220;react&#8221;: &#8220;^18.2.0&#8221;,<br \/>\n&#8220;typescript&#8221;: &#8220;^4.9.5&#8221; \u5e93\u7248\u672c<\/p>\n<h2>\u6211\u4e3a\u4ec0\u4e48\u60f3\u8981\u5199\u8fd9\u7bc7\u6587\u7ae0\u5462\uff1f<\/h2>\n<p>\u5c3d\u7ba1\u5173\u4e8e\u4f7f\u7528styled-components\u7684Theme-Provider\u7684\u8d44\u6599\u5f88\u591a\uff0c\u4f46\u6211\u8fd8\u662f\u89c9\u5f97\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\uff0c\u6ca1\u6709\u592a\u591a\u53ef\u4ee5\u4e00\u773c\u5c31\u4e0a\u624b\u7684\u8d44\u6599\u3002\u56e0\u6b64\uff0c\u4e3a\u4e86\u5907\u5fd8\u5e76\u65b9\u4fbf\u4f7f\u7528\uff0c\u6211\u51c6\u5907\u4e86\u4e00\u4efd\u53ef\u4ee5\u7acb\u5373\u4f7f\u7528\u7684\u6a21\u677f\u8d44\u6599\u3002<\/p>\n<p>\u6211\u4e00\u76f4\u4ee5\u4e3aTheme-Provider\u5c31\u662f\u5168\u5c40CSS\uff0c\u4f46\u540e\u6765\u624d\u53d1\u73b0\u6211\u9519\u4e86\u3002\u5728\u5199\u4f5c\u8fc7\u7a0b\u4e2d\u5f97\u77e5\u4e86\u8fd9\u4e2a\u3002<\/p>\n<p>Theme-Provider\u662f\u4e00\u79cd\u5de5\u5177\uff0c\u7528\u4e8e\u4e3aReact\u7ec4\u4ef6\u6811\u4e2d\u7684\u6240\u6709\u5e26\u6709\u6837\u5f0f\u7684\u7ec4\u4ef6\u63d0\u4f9b\u4e3b\u9898\u3002<\/p>\n<p>\u5173\u4e8e\u5168\u5c40CSS\uff0c\u6211\u4eec\u5c06\u5728\u8d44\u6599\u9879\u76ee\u7684\u6700\u540e\u4f5c\u4e3a\u8865\u5145\u8fdb\u884c\u8bf4\u660e\u3002<\/p>\n<h2>\u9996\u5148\u4f7f\u7528npm\u547d\u4ee4\u8fdb\u884cstyled-components\u7684\u5b89\u88c5\u3002<\/h2>\n<pre class=\"post-pre\"><code>npm install styled-components @types\/styled-components\r\n<\/code><\/pre>\n<p>\u56e0\u4e3a\u8fd9\u91cc\u5927\u90e8\u5206\u7684\u4eba\u90fd\u5df2\u7ecf\u7406\u89e3\u4e86\uff0c\u6240\u4ee5\u6211\u5c31\u4e0d\u9700\u8981\u7279\u522b\u89e3\u91ca\u4e86\u3002<\/p>\n<h2>\u5728src\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3atheme\u7684\u6587\u4ef6\u5939\u3002<\/h2>\n<p>\u6211\u6b63\u5728\u4f7f\u7528create-react-app\u7ed3\u6784\u6765\u521b\u5efa\u3002<br \/>\n\u5728src\u6587\u4ef6\u5939\u4e0b\u521b\u5efa\u4e00\u4e2atheme\u76ee\u5f55\uff0c\u5e76\u5728theme\u76ee\u5f55\u4e0b\u521b\u5efatheme.ts\u6587\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code>src\r\n -theme\r\n  -theme.ts\r\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u3002<\/p>\n<h2>theme.ts\u7684\u793a\u4f8b\u4ee3\u7801<\/h2>\n<pre class=\"post-pre\"><code>export const theme = {\r\n  color: {\r\n    mainColor: \"red\",\r\n    subColor: \"blue,\r\n  },\r\n}\r\n<\/code><\/pre>\n<p>\u8fd9\u662ftheme.ts\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5df2\u7ecf\u5b8c\u6210\u4e86\u3002\u6839\u636e\u9700\u8981\uff0c\u6211\u4eec\u53ef\u4ee5\u5728theme\u5185\u6dfb\u52a0\u5c5e\u6027\u3002<br \/>\n\u6839\u636e\u5b9e\u9645\u9700\u6c42\uff0c\u6dfb\u52a0\u5fc5\u8981\u7684\u5c5e\u6027\u5c31\u53ef\u4ee5\u4e86\u3002\u8fd9\u6b21\u7684\u76ee\u6807\u662f\u5148\u5c1d\u8bd5\u4e00\u4e0b\uff0c\u6240\u4ee5\u53ea\u5305\u542b\u4e86\u6700\u57fa\u672c\u7684\u989c\u8272\u3002<\/p>\n<h2>\u7f16\u8f91index.tsx\u6587\u4ef6<\/h2>\n<pre class=\"post-pre\"><code>import React from \"react\";\r\nimport ReactDOM from \"react-dom\/client\";\r\nimport App from \".\/App\";\r\nimport { ThemeProvider } from \"styled-components\";\r\nimport { theme } from \".\/theme\/theme\";\r\n\r\nconst root = ReactDOM.createRoot(\r\n  document.getElementById(\"root\") as HTMLElement\r\n);\r\nroot.render(\r\n  &lt;React.StrictMode&gt;\r\n    &lt;ThemeProvider theme={theme}&gt;\r\n        &lt;App \/&gt;\r\n    &lt;\/ThemeProvider&gt;\r\n  &lt;\/React.StrictMode&gt;\r\n);\r\n<\/code><\/pre>\n<p>\u901a\u8fc7import theme.ts\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3aProps\u4f20\u9012\u7ed9ThemeProvider\uff0c\u53ef\u4ee5\u5c06theme\u4fe1\u606f\u5e94\u7528\u4e8e\u7ec4\u4ef6\u7684\u6240\u6709\u4e0b\u5c42\uff08\u5305\u62ecApp\u4ee5\u4e0b\uff09\u7684\u5e26\u6709\u6837\u5f0f\u7684\u7ec4\u4ef6\u3002<\/p>\n<h2>\u5c1d\u8bd5\u5c06\u5b9e\u9645\u7684\u7ec4\u4ef6\u8fdb\u884c\u63cf\u8ff0<\/h2>\n<pre class=\"post-pre\"><code>import React, { FC } from \"react\";\r\nimport styled from \"styled-components\";\r\n\r\ntype Props = {\r\n  children: React.ReactNode;\r\n};\r\n\r\ntype ButtonProps = React.ComponentPropsWithoutRef&lt;\"button\"&gt;;\r\n\r\nconst Button: FC&lt;Props &amp; ButtonProps&gt; = ({ children, ...other }) =&gt; {\r\n  return &lt;SButton {...other}&gt;{children}&lt;\/SButton&gt;;\r\n};\r\n\r\nexport default Button;\r\n\r\nconst SButton = styled.button`\r\n  color: ${({ theme }) =&gt; theme.color.mainColor};\r\n  background-color: ${({ theme }) =&gt; theme.color.subColor};\r\n`;\r\n<\/code><\/pre>\n<p>\u6211\u5df2\u7ecf\u51c6\u5907\u597d\u4e00\u4e2a\u6309\u94ae\u7ec4\u4ef6\uff0c\u80fd\u591f\u63a5\u6536&#8221;chileren&#8221;\u4f5c\u4e3a&#8221;Props&#8221;\u3002<\/p>\n<p>\u203b\u8fd9\u91cc\u5199\u4e86ComponentPropsWithoutRef\uff0c\u867d\u7136\u8fd9\u5728\u5f53\u524d\u6587\u6863\u4e2d\u4e0d\u662f\u91cd\u8981\u7684\u5185\u5bb9\uff0c\u4f46\u4e3a\u4e86\u8865\u5145\uff0c\u6211\u4f1a\u5199\u4e0b\u6765\u3002<br \/>\n\u26aa\ufe0e\u63d0\u53d6HTML\u6309\u94ae\u5143\u7d20\u7684\u5c5e\u6027\uff1a&lt;&#8220;button&#8221;&gt;\u6307\u7684\u662fHTML\u5143\u7d20\u3002\u8fd9\u6bb5\u4ee3\u7801\u83b7\u53d6\u4e86\u6807\u51c6\u7684HTML\u6309\u94ae\u5143\u7d20\u5177\u6709\u7684\u6240\u6709\u5c5e\u6027\uff08\u4f8b\u5982onClick\uff0cdisabled\u7b49\uff09\u7684\u7c7b\u578b\u3002<br \/>\n\u26aa\ufe0e\u6392\u9664ref\u5c5e\u6027\uff1aComponentPropsWithoutRef\u6392\u9664\u4e86ref\u5c5e\u6027\u3002\u8fd9\u662f\u56e0\u4e3aref\u5728\u5904\u7406\u4e0a\u6709\u7279\u6b8a\u7684\u89c4\u5b9a\uff0c\u6240\u4ee5\u901a\u5e38\u4ee5\u4e0d\u540c\u7684\u65b9\u5f0f\u5904\u7406\u5e38\u89c4\u5c5e\u6027\u3002<br \/>\n\u26aa\ufe0e\u7b80\u5355\u6765\u8bf4\uff0c\u5c31\u662f\u8ba9\u6211\u4eec\u80fd\u591f\u4f7f\u7528\u6309\u94ae\u5e38\u7528\u7684onClick\u548cdisabled\u7b49\u6807\u51c6\u5c5e\u6027\u3002<\/p>\n<h2>\u8c03\u7528\u548c\u7ed3\u679c\uff0c\u7531\u6211\u521b\u5efa\u7684\u6309\u94ae\u7ec4\u4ef6\u751f\u6210\u3002<\/h2>\n<pre class=\"post-pre\"><code>import React, { FC } from \"react\";\r\nimport Button from \"..\/..\/01atoms\/Button\";\r\n\r\n\r\nconst TopLayout: FC = () =&gt; {\r\n  return (\r\n    &lt;&gt;\r\n      &lt;Button&gt;\u5b8c\u6210\u3057\u305f\u30dc\u30bf\u30f3\u304c\u3053\u3061\u3089&lt;\/Button&gt;\r\n    &lt;\/&gt;\r\n  );\r\n};\r\n\r\nexport default TopLayout;\r\n<\/code><\/pre>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d329037434c4406c62a20\/27-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3 \u30b7\u30e7\u30c3\u30c8 2023-11-19 \u306b 23.06.13 \u5348\u5f8c.png\" \/><\/div>\n<h2>\u5bf9\u8fd9\u4e2a\u95ee\u9898\u7684\u6240\u601d\u6240\u611f<\/h2>\n<p>\u867d\u7136\u6309\u94ae\u7684\u5916\u89c2\u770b\u8d77\u6765\u6709\u70b9\u4e0d\u592a\u597d\uff0c\u4f46\u6211\u8ba4\u4e3a\u4f7f\u7528themeProvider\u53ef\u4ee5\u7406\u89e3\u5176\u4f7f\u7528\u65b9\u5f0f\u3002\u5982\u4f55\u7ba1\u7406Provider\u7684\u5185\u5bb9\u5c06\u662f\u4e00\u4e2a\u672a\u6765\u7684\u95ee\u9898\u3002<\/p>\n<h2>\u88dc\u5145<\/h2>\n<p>\u987a\u4fbf\u95ee\u4e00\u4e0b\uff0c\u4ec0\u4e48\u662f\u5168\u5c40CSS\u5462\uff1f<br \/>\n\u4f5c\u4e3a\u7ed3\u679c\uff0c\u6211\u8ba4\u4e3a\u5b83\u6307\u7684\u662f\u50cfApp.tsx\u8fd9\u6837\u52a0\u8f7d\u7684CSS\uff08\u53ef\u80fd\u662fstyle.css\u4e4b\u7c7b\u7684\uff09\u3002<br \/>\n\u5728styled-components\u4e2d\uff0c\u4f3c\u4e4e\u6709\u4e00\u4e2a\u540d\u4e3acreateGlobalStyle\u7684\u529f\u80fd\uff0c\u4f46\u662f\u56e0\u4e3a\u4ee3\u7801\u4f1a\u53d8\u5f97\u7a0d\u5fae\u957f\u4e00\u4e9b\uff0c\u6240\u4ee5\u6211\u4e0d\u592a\u559c\u6b22\u5b83\u3002<\/p>\n<p>\u5728 App.tsx \u6587\u4ef6\u4e2d\uff0cimport src \u76ee\u5f55\u4e0b\u7684 style.css \u6587\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code>import React from \"react\";\r\nimport \"reset.css\";\r\nimport \".\/style.css\";\r\nimport ReactRouter from \".\/compornents\/05pages\/ReactRouter\";\r\n\r\nfunction App() {\r\n  return (\r\n    &lt;div className=\"App\"&gt;\r\n      &lt;ReactRouter \/&gt;\r\n    &lt;\/div&gt;\r\n  );\r\n}\r\n\r\nexport default App;\r\n<\/code><\/pre>\n<p>\u5728\u6211\u521b\u5efa\u7684src\u6587\u4ef6\u5939\u4e2d\u7684style.css\u6587\u4ef6\u4e2d\uff0c\u4e3b\u8981\u4f7f\u7528box-sizing\u548c\u6309\u94ae\u60ac\u505c\u65f6\u7684\u53d8\u5316\u65f6\u95f4\u7b49\u3002<\/p>\n<pre class=\"post-pre\"><code>*, *:before, *:after {\r\n  -webkit-box-sizing: border-box;\r\n  box-sizing: border-box\r\n}\r\n\r\nbody {\r\n  background-color: lemonchiffon;\r\n}\r\n\r\nbutton {\r\n  &amp;:hover {\r\n    transition: all 0.8s;\r\n  }\r\n}\r\n<\/code><\/pre>\n<p>\u8c22\u8c22\u60a8\u7684\u6d4f\u89c8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u5f55 \u5f00\u53d1\u73af\u5883 &nbsp; \u4e3a\u4ec0\u4e48\u60f3\u8981\u5199\u8fd9\u7bc7\u6587\u7ae0 &nbsp; \u9996\u5148\uff0c\u5728npm\u4e2d\u6267\u884cstyled-compo [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-38153","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme-provider\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider\" \/>\n<meta property=\"og:description\" content=\"\u76ee\u5f55 \u5f00\u53d1\u73af\u5883 &nbsp; \u4e3a\u4ec0\u4e48\u60f3\u8981\u5199\u8fd9\u7bc7\u6587\u7ae0 &nbsp; \u9996\u5148\uff0c\u5728npm\u4e2d\u6267\u884cstyled-compo [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme-provider\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2024-02-15T21:29:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-29T12:57:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d329037434c4406c62a20\/27-0.png\" \/>\n<meta name=\"author\" content=\"\u79d1, \u96c5\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u79d1, \u96c5\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/\",\"name\":\"\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2024-02-15T21:29:50+00:00\",\"dateModified\":\"2024-04-29T12:57:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a\",\"name\":\"\u79d1, \u96c5\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g\",\"caption\":\"\u79d1, \u96c5\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme-provider\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider","og_description":"\u76ee\u5f55 \u5f00\u53d1\u73af\u5883 &nbsp; \u4e3a\u4ec0\u4e48\u60f3\u8981\u5199\u8fd9\u7bc7\u6587\u7ae0 &nbsp; \u9996\u5148\uff0c\u5728npm\u4e2d\u6267\u884cstyled-compo [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme-provider\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2024-02-15T21:29:50+00:00","article_modified_time":"2024-04-29T12:57:22+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d329037434c4406c62a20\/27-0.png"}],"author":"\u79d1, \u96c5","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u79d1, \u96c5","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/","name":"\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2024-02-15T21:29:50+00:00","dateModified":"2024-04-29T12:57:22+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528styled-components\u5c1d\u8bd5\u4f7f\u7528theme Provider"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/41e222757cdd2a3365361328bd79970a","name":"\u79d1, \u96c5","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1b2d3e00a7df03689797ebd4af8c5827ba5af936849a71050ec331f4cf902c5d?s=96&d=mm&r=g","caption":"\u79d1, \u96c5"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/keya\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8styled-components%e5%b0%9d%e8%af%95%e4%bd%bf%e7%94%a8theme-provider\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=38153"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38153\/revisions"}],"predecessor-version":[{"id":87601,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38153\/revisions\/87601"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=38153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=38153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=38153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}