{"id":38591,"date":"2023-03-11T22:15:29","date_gmt":"2024-01-03T05:09:39","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/"},"modified":"2024-04-29T18:28:54","modified_gmt":"2024-04-29T10:28:54","slug":"react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/","title":{"rendered":"React\u4e2d &#8220;Context&#8221; \u7684\u7528\u6cd5\u548c\u597d\u5904"},"content":{"rendered":"<p>React\u7684Context\u662f\u4e00\u79cd\u63d0\u4f9b\u6574\u4e2a\u7ec4\u4ef6\u6811\u6570\u636e\u7684\u65b9\u6cd5\u3002\u4e0d\u9700\u8981\u4f7f\u7528props\u624b\u52a8\u5c06\u6570\u636e\u4f20\u9012\u7ed9\u6bcf\u4e2a\u7ec4\u4ef6\uff0c\u800c\u662f\u4f7f\u7528Context\u53ef\u4ee5\u5728\u7ec4\u4ef6\u6811\u7684\u4efb\u4f55\u5c42\u7ea7\u4e0a\u8bbf\u95ee\u6570\u636e\u3002<\/p>\n<h1>\u4e3a\u4f55\u9700\u8981React\u7684Context\uff1a<\/h1>\n<p>\u573a\u666f: \u8bf7\u601d\u8003\u4e00\u4e2a\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f\u3002\u8be5\u5e94\u7528\u6709\u8bb8\u591a\u7ec4\u4ef6\uff0c\u5b83\u4eec\u5d4c\u5957\u5e76\u5177\u6709\u590d\u6742\u7684\u7ed3\u6784\u3002\u5f53\u7528\u6237\u767b\u5f55\u8be5\u5e94\u7528\u65f6\uff0c\u7528\u6237\u4fe1\u606f\uff08\u4f8b\u5982\u59d3\u540d\u3001\u4e2a\u4eba\u7167\u7247\u3001\u8bbe\u7f6e\u7b49\uff09\u5c06\u5728\u8bb8\u591a\u7ec4\u4ef6\u4e2d\u88ab\u9700\u8981\u3002<\/p>\n<p>\u554f\u984c: \u3053\u306e\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u3001\u4e0a\u4f4d\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304b\u3089\u4e0b\u4f4d\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3078\u3068props\u3092\u4f7f\u3063\u3066\u4e00\u3064\u4e00\u3064\u6e21\u3057\u3066\u3044\u304f\u306e\u306f\u3001\u975e\u5e38\u306b\u624b\u9593\u304c\u304b\u304b\u308a\u3001\u7ba1\u7406\u304c\u96e3\u3057\u304f\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u3088\u3046\u306a\u624b\u6cd5\u3092\u300cprop drilling\u300d\u3068\u547c\u3073\u307e\u3059\u3002<\/p>\n<p>\u89e3\u6c7a\u7b56: \u3053\u3053\u3067Context\u304c\u5f79\u7acb\u3061\u307e\u3059\u3002Context\u3092\u4f7f\u3046\u3068\u3001\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u3069\u3053\u304b\u3089\u3067\u3082\u76f4\u63a5\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u3064\u307e\u308a\u3001\u4e2d\u9593\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u7d4c\u7531\u305b\u305a\u306b\u3001\u5fc5\u8981\u306a\u60c5\u5831\u3092\u76f4\u63a5\u53d6\u5f97\u3067\u304d\u308b\u306e\u3067\u3059\u3002<\/p>\n<h2>\u5177\u4f53\u7684\u4f18\u52bf\uff1a<\/h2>\n<p>\u30b3\u30fc\u30c9\u306e\u30b7\u30f3\u30d7\u30eb\u3055: \u4e2d\u9593\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u4e0d\u8981\u306a\u30c7\u30fc\u30bf\u3092\u6301\u305f\u306a\u304f\u306a\u308b\u305f\u3081\u3001\u30b3\u30fc\u30c9\u304c\u30b7\u30f3\u30d7\u30eb\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u518d\u5229\u7528\u6027: \u5404\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u72ec\u7acb\u3057\u3066\u30c7\u30fc\u30bf\u306b\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u305f\u3081\u3001\u4ed6\u306e\u5834\u6240\u3067\u518d\u5229\u7528\u3059\u308b\u306e\u304c\u5bb9\u6613\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4e00\u8cab\u6027: \u30c7\u30fc\u30bf\u306e\u30bd\u30fc\u30b9\u304c\u4e00\u7b87\u6240\u306b\u96c6\u7d04\u3055\u308c\u308b\u305f\u3081\u3001\u30c7\u30fc\u30bf\u306e\u4e0d\u6574\u5408\u3084\u30d0\u30b0\u3092\u9632\u3050\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>\u4e0a\u4e0b\u6587\u7684\u5e94\u7528\u65b9\u5f0f\u3002<\/h2>\n<p>Context\u306e\u4f5c\u6210: React.createContext\u3092\u4f7f\u7528\u3057\u3066Context\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p>Provider\u306e\u4f7f\u7528: \u4f5c\u6210\u3057\u305fContext\u306eProvider\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u4f7f\u7528\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092\u63d0\u4f9b\u3059\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u30c4\u30ea\u30fc\u3092\u30e9\u30c3\u30d7\u3057\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u306e\u5229\u7528: useContext Hook\u3084Context.Consumer\u3092\u4f7f\u7528\u3057\u3066\u3001\u30c7\u30fc\u30bf\u3092\u5fc5\u8981\u3068\u3059\u308b\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<h2>\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/h2>\n<pre class=\"post-pre\"><code><span class=\"k\">import<\/span> <span class=\"nx\">React<\/span><span class=\"p\">,<\/span> <span class=\"p\">{<\/span> <span class=\"nx\">useContext<\/span> <span class=\"p\">}<\/span> <span class=\"k\">from<\/span> <span class=\"dl\">'<\/span><span class=\"s1\">react<\/span><span class=\"dl\">'<\/span><span class=\"p\">;<\/span>\r\n\r\n<span class=\"c1\">\/\/ 1. \u65b0\u3057\u3044Context\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u308c\u306f\u30c6\u30fc\u30de\u60c5\u5831\uff08'light'\u3084'dark'\u306a\u3069\uff09\u3092\u6301\u3064\u3053\u3068\u3092\u60f3\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/span>\r\n<span class=\"kd\">const<\/span> <span class=\"nx\">ThemeContext<\/span> <span class=\"o\">=<\/span> <span class=\"nx\">React<\/span><span class=\"p\">.<\/span><span class=\"nf\">createContext<\/span><span class=\"p\">(<\/span><span class=\"dl\">'<\/span><span class=\"s1\">light<\/span><span class=\"dl\">'<\/span><span class=\"p\">);<\/span>\r\n\r\n<span class=\"kd\">function<\/span> <span class=\"nf\">App<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span>\r\n  <span class=\"k\">return <\/span><span class=\"p\">(<\/span>\r\n    <span class=\"c1\">\/\/ 2. ThemeContext.Provider\u3092\u4f7f\u3063\u3066\u3001\u5185\u90e8\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u30c6\u30fc\u30de\u60c5\u5831\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002<\/span>\r\n    <span class=\"c1\">\/\/ \u3053\u306e\u4f8b\u3067\u306f\u3001\u5168\u4f53\u306e\u30c6\u30fc\u30de\u3092'dark'\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u307e\u3059\u3002<\/span>\r\n    <span class=\"o\">&lt;<\/span><span class=\"nx\">ThemeContext<\/span><span class=\"p\">.<\/span><span class=\"nx\">Provider<\/span> <span class=\"nx\">value<\/span><span class=\"o\">=<\/span><span class=\"dl\">\"<\/span><span class=\"s2\">dark<\/span><span class=\"dl\">\"<\/span><span class=\"o\">&gt;<\/span>\r\n      <span class=\"o\">&lt;<\/span><span class=\"nx\">Toolbar<\/span> <span class=\"o\">\/&gt;<\/span>\r\n    <span class=\"o\">&lt;<\/span><span class=\"sr\">\/ThemeContext.Provider<\/span><span class=\"err\">&gt;\r\n<\/span>  <span class=\"p\">);<\/span>\r\n<span class=\"p\">}<\/span>\r\n\r\n<span class=\"kd\">function<\/span> <span class=\"nf\">Toolbar<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span>\r\n  <span class=\"c1\">\/\/ Toolbar\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306f\u30c6\u30fc\u30de\u60c5\u5831\u3092\u76f4\u63a5\u4f7f\u7528\u3057\u307e\u305b\u3093\u304c\u3001\u5185\u90e8\u306eButton\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u304c\u305d\u308c\u3092\u4f7f\u7528\u3059\u308b\u305f\u3081\u3001<\/span>\r\n  <span class=\"c1\">\/\/ ThemeContext\u306e\u60c5\u5831\u3092\u53d7\u3051\u53d6\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/span>\r\n  <span class=\"k\">return<\/span> <span class=\"o\">&lt;<\/span><span class=\"nx\">Button<\/span> <span class=\"o\">\/&gt;<\/span><span class=\"p\">;<\/span>\r\n<span class=\"p\">}<\/span>\r\n\r\n<span class=\"kd\">function<\/span> <span class=\"nf\">Button<\/span><span class=\"p\">()<\/span> <span class=\"p\">{<\/span>\r\n  <span class=\"c1\">\/\/ 3. useContext\u3092\u4f7f\u3063\u3066\u3001\u73fe\u5728\u306e\u30c6\u30fc\u30de\u60c5\u5831\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/span>\r\n  <span class=\"kd\">const<\/span> <span class=\"nx\">theme<\/span> <span class=\"o\">=<\/span> <span class=\"nf\">useContext<\/span><span class=\"p\">(<\/span><span class=\"nx\">ThemeContext<\/span><span class=\"p\">);<\/span>\r\n  <span class=\"c1\">\/\/ \u53d6\u5f97\u3057\u305f\u30c6\u30fc\u30de\u60c5\u5831\u3092\u4f7f\u3063\u3066\u3001\u30dc\u30bf\u30f3\u306e\u30e9\u30d9\u30eb\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/span>\r\n  <span class=\"k\">return<\/span> <span class=\"o\">&lt;<\/span><span class=\"nx\">button<\/span><span class=\"o\">&gt;<\/span><span class=\"p\">{<\/span><span class=\"nx\">theme<\/span><span class=\"p\">}<\/span><span class=\"nx\">\u30c6\u30fc\u30de\u306e\u30dc\u30bf\u30f3<\/span><span class=\"o\">&lt;<\/span><span class=\"sr\">\/button&gt;<\/span><span class=\"err\">;\r\n<\/span><span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3aThemeContext\u7684\u65b0Context\u3002\u8fd9\u4e2aContext\u7528\u6765\u5b58\u50a8\u5e94\u7528\u7a0b\u5e8f\u7684\u4e3b\u9898\u4fe1\u606f\uff08\u4f8b\u5982&#8217;light&#8217;\u6216&#8217;dark&#8217;\uff09\u3002<br \/>\n\u4f20\u9012\u7ed9React.createContext\u7684&#8217;light&#8217;\u662f\u8fd9\u4e2aContext\u7684\u9ed8\u8ba4\u503c\u3002\u6362\u53e5\u8bdd\u8bf4\uff0c\u5982\u679c\u4f7f\u7528ThemeContext\u7684\u7ec4\u4ef6\u5728\u4efb\u4f55ThemeContext.Provider\u7684\u5185\u90e8\u90fd\u4e0d\u5b58\u5728\uff0c\u90a3\u4e48\u5c06\u4f7f\u7528\u8fd9\u4e2a\u9ed8\u8ba4\u503c\u3002<\/p>\n<p>\u901a\u8fc7\u4f7f\u7528\u4e0a\u4e0b\u6587\uff0c\u60a8\u53ef\u4ee5\u5728\u4e0d\u9700\u8981\u76f4\u63a5\u5173\u7cfb\u7684\u60c5\u51b5\u4e0b\u5c06\u6570\u636e\u4ece\u7236\u7ec4\u4ef6\u4f20\u9012\u5230\u5b50\u7ec4\u4ef6\u4e2d\u3002<\/p>\n<h2>\u4f8b\u5b50\uff1a<\/h2>\n<p>\u53ef\u4ee5\u8003\u8651\u4ee5\u4e0b\u5b9e\u9645\u4f7f\u7528\u573a\u666f\u4f5c\u4e3a\u4f8b\u5b50:<\/p>\n<p>\u30c6\u30fc\u30de\u8a2d\u5b9a: \u30e6\u30fc\u30b6\u30fc\u304c\u30a2\u30d7\u30ea\u306e\u30ab\u30e9\u30fc\u30c6\u30fc\u30de\uff08\u30c0\u30fc\u30af\u30e2\u30fc\u30c9\u3084\u30e9\u30a4\u30c8\u30e2\u30fc\u30c9\u306a\u3069\uff09\u3092\u9078\u629e\u3067\u304d\u308b\u5834\u5408\u3001\u305d\u306e\u8a2d\u5b9a\u3092\u30a2\u30d7\u30ea\u5168\u4f53\u3067\u5229\u7528\u3059\u308b\u305f\u3081\u306bContext\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u8a00\u8a9e\u8a2d\u5b9a: \u591a\u8a00\u8a9e\u5bfe\u5fdc\u306e\u30a2\u30d7\u30ea\u3067\u306f\u3001\u9078\u629e\u3055\u308c\u305f\u8a00\u8a9e\u306b\u57fa\u3065\u3044\u3066\u30c6\u30ad\u30b9\u30c8\u3092\u8868\u793a\u3059\u308b\u305f\u3081\u306bContext\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u8a8d\u8a3c: \u30e6\u30fc\u30b6\u30fc\u306e\u30ed\u30b0\u30a4\u30f3\u72b6\u614b\u3084\u6a29\u9650\u306b\u5fdc\u3058\u3066\u3001\u7279\u5b9a\u306e\u6a5f\u80fd\u3092\u5236\u9650\u3059\u308b\u305f\u3081\u306bContext\u3067\u30e6\u30fc\u30b6\u30fc\u60c5\u5831\u3092\u7ba1\u7406\u3057\u307e\u3059\u3002<\/p>\n<h1>\u603b\u7ed3<\/h1>\n<p>\u4f55\u304c\u3067\u304d\u308b\u306e\u304b: React\u306eContext\u306f\u3001\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u9593\u3067\u30c7\u30fc\u30bf\u3092\u52b9\u679c\u7684\u306b\u5171\u6709\u3059\u308b\u305f\u3081\u306e\u624b\u6bb5\u3092\u63d0\u4f9b\u3057\u307e\u3059\u3002\u3053\u308c\u306b\u3088\u308a\u3001\u30c7\u30fc\u30bf\u3092\u624b\u52d5\u3067\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306e\u968e\u5c64\u3092\u901a\u3057\u3066\u6e21\u3059\u5fc5\u8981\u304c\u306a\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4e3b\u306a\u7528\u9014: \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u3001\u30e6\u30fc\u30b6\u30fc\u306e\u8a8d\u8a3c\u60c5\u5831\u3001\u8a00\u8a9e\u8a2d\u5b9a\u3001\u30c6\u30fc\u30de\u306a\u3069\u3001\u591a\u304f\u306e\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3067\u4f7f\u308f\u308c\u308b\u30c7\u30fc\u30bf\u3084\u8a2d\u5b9a\u3092\u6271\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f7f\u7528\u65b9\u6cd5: React.createContext\u3067\u65b0\u3057\u3044Context\u3092\u4f5c\u6210\u3057\u3001Context.Provider\u3067\u30c7\u30fc\u30bf\u3092\u63d0\u4f9b\u3057\u3001useContext\u3084Context.Consumer\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u5024: Context\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u5024\u3092\u6301\u3064\u3053\u3068\u304c\u3067\u304d\u3001Provider\u304c\u63d0\u4f9b\u3059\u308b\u5024\u304c\u306a\u3044\u5834\u5408\u306b\u4f7f\u7528\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u5229\u70b9: Context\u306f\u300cprop drilling\u300d\u3068\u3044\u3046\u554f\u984c\u3092\u89e3\u6c7a\u3059\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002\u3053\u308c\u306f\u3001\u30c7\u30fc\u30bf\u3092\u6df1\u304f\u30cd\u30b9\u30c8\u3055\u308c\u305f\u5b50\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u306b\u624b\u52d5\u3067\u6e21\u3059\u5fc5\u8981\u304c\u3042\u308b\u5834\u5408\u306b\u767a\u751f\u3059\u308b\u554f\u984c\u3067\u3059\u3002<\/p>\n<p>\u6ce8\u610f\u70b9: Context\u3092\u904e\u5ea6\u306b\u4f7f\u7528\u3059\u308b\u3068\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u69cb\u9020\u304c\u8907\u96d1\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002\u9069\u5207\u306a\u5834\u9762\u3067\u306e\u307f\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>React\u7684Context\u662f\u4e00\u79cd\u63d0\u4f9b\u6574\u4e2a\u7ec4\u4ef6\u6811\u6570\u636e\u7684\u65b9\u6cd5\u3002\u4e0d\u9700\u8981\u4f7f\u7528props\u624b\u52a8\u5c06\u6570\u636e\u4f20\u9012\u7ed9\u6bcf\u4e2a\u7ec4\u4ef6\uff0c\u800c\u662f\u4f7f [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-38591","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>React\u4e2d &quot;Context&quot; \u7684\u7528\u6cd5\u548c\u597d\u5904 - 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\/react\u4e2d-context-\u7684\u7528\u6cd5\u548c\u597d\u5904\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"React\u4e2d &quot;Context&quot; \u7684\u7528\u6cd5\u548c\u597d\u5904\" \/>\n<meta property=\"og:description\" content=\"React\u7684Context\u662f\u4e00\u79cd\u63d0\u4f9b\u6574\u4e2a\u7ec4\u4ef6\u6811\u6570\u636e\u7684\u65b9\u6cd5\u3002\u4e0d\u9700\u8981\u4f7f\u7528props\u624b\u52a8\u5c06\u6570\u636e\u4f20\u9012\u7ed9\u6bcf\u4e2a\u7ec4\u4ef6\uff0c\u800c\u662f\u4f7f [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/react\u4e2d-context-\u7684\u7528\u6cd5\u548c\u597d\u5904\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-03T05:09:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-29T10:28:54+00:00\" \/>\n<meta name=\"author\" content=\"\u96c5, \u609f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u96c5, \u609f\" \/>\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\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/\",\"name\":\"React\u4e2d \\\"Context\\\" \u7684\u7528\u6cd5\u548c\u597d\u5904 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2024-01-03T05:09:39+00:00\",\"dateModified\":\"2024-04-29T10:28:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"React\u4e2d &#8220;Context&#8221; \u7684\u7528\u6cd5\u548c\u597d\u5904\"}]},{\"@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\/f044a4b7fa4ee2701702942002419ca6\",\"name\":\"\u96c5, \u609f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"caption\":\"\u96c5, \u609f\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"React\u4e2d \"Context\" \u7684\u7528\u6cd5\u548c\u597d\u5904 - 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\/react\u4e2d-context-\u7684\u7528\u6cd5\u548c\u597d\u5904\/","og_locale":"zh_CN","og_type":"article","og_title":"React\u4e2d \"Context\" \u7684\u7528\u6cd5\u548c\u597d\u5904","og_description":"React\u7684Context\u662f\u4e00\u79cd\u63d0\u4f9b\u6574\u4e2a\u7ec4\u4ef6\u6811\u6570\u636e\u7684\u65b9\u6cd5\u3002\u4e0d\u9700\u8981\u4f7f\u7528props\u624b\u52a8\u5c06\u6570\u636e\u4f20\u9012\u7ed9\u6bcf\u4e2a\u7ec4\u4ef6\uff0c\u800c\u662f\u4f7f [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/react\u4e2d-context-\u7684\u7528\u6cd5\u548c\u597d\u5904\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2024-01-03T05:09:39+00:00","article_modified_time":"2024-04-29T10:28:54+00:00","author":"\u96c5, \u609f","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u96c5, \u609f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"1 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/","name":"React\u4e2d \"Context\" \u7684\u7528\u6cd5\u548c\u597d\u5904 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2024-01-03T05:09:39+00:00","dateModified":"2024-04-29T10:28:54+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"React\u4e2d &#8220;Context&#8221; \u7684\u7528\u6cd5\u548c\u597d\u5904"}]},{"@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\/f044a4b7fa4ee2701702942002419ca6","name":"\u96c5, \u609f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","caption":"\u96c5, \u609f"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/react%e4%b8%ad-context-%e7%9a%84%e7%94%a8%e6%b3%95%e5%92%8c%e5%a5%bd%e5%a4%84\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38591","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\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=38591"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38591\/revisions"}],"predecessor-version":[{"id":86911,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/38591\/revisions\/86911"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=38591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=38591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=38591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}