\"}),\" \\u5BB9\\u5668\\u3002 \\u5F53\\u52A8\\u6001\\u6DFB\\u52A0\\u5E76\\u5355\\u51FB\\u4E00\\u4E2A\\u65B0\\u6309\\u94AE\\u65F6\\uFF0C\\u5BB9\\u5668\\u4E0A\\u7684\\u4E8B\\u4EF6\\u4FA6\\u542C\\u5668\\u4F1A\\u5904\\u7406 click \\u4E8B\\u4EF6\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u901A\\u8FC7\\u907F\\u514D\\u4E3A\\u66F4\\u6539\\u7684\\u5143\\u7D20\\u9644\\u52A0\\u548C\\u5220\\u9664\\u4E8B\\u4EF6\\u4FA6\\u542C\\u5668\\u6765\\u7B80\\u5316\\u4EE3\\u7801\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-js\",children:`// HTML:\n//
\n\nconst userForm = document.getElementById('user-form');\n\nuserForm.addEventListener('input', (event) => {\n const { name, value } = event.target;\n console.log(\\`Changed \\${name}: \\${value}\\`);\n});\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u8FD9\\u4E2A\\u4F8B\\u5B50\\u4E2D\\uFF0C\\u5355\\u4E2A\\u8F93\\u5165\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u9644\\u52A0\\u5230\\u8868\\u5355\\u5143\\u7D20\\u3002\\u5B83\\u53EF\\u4EE5\\u54CD\\u5E94\\u6240\\u6709\\u5B50\\u8F93\\u5165\\u5143\\u7D20\\u7684\\u8F93\\u5165\\u66F4\\u6539\\uFF0C\\u901A\\u8FC7\\u6D88\\u9664\\u5BF9\\u6BCF\\u4E2A\",(0,e.jsx)(n.code,{children:\"
\"}),\"\\u5143\\u7D20\\u4E0A\\u5355\\u72EC\\u76D1\\u542C\\u5668\\u7684\\u9700\\u6C42\\u6765\\u7B80\\u5316\\u4EE3\\u7801\\u3002\"]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u9677\\u9631\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8BF7\\u6CE8\\u610F\\uFF0C\\u4E8B\\u4EF6\\u59D4\\u6258\\u4F1A\\u5E26\\u6765\\u67D0\\u4E9B\\u9677\\u9631\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u76EE\\u6807\\u5904\\u7406\\u4E0D\\u6B63\\u786E\\uFF1A\"}),\" \\u786E\\u4FDD\\u6B63\\u786E\\u8BC6\\u522B\\u4E8B\\u4EF6\\u76EE\\u6807\\uFF0C\\u4EE5\\u907F\\u514D\\u610F\\u5916\\u64CD\\u4F5C\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5E76\\u975E\\u6240\\u6709\\u4E8B\\u4EF6\\u90FD\\u53EF\\u4EE5\\u59D4\\u6258/\\u5192\\u6CE1\"}),\"\\uFF1A\\u5E76\\u975E\\u6240\\u6709\\u4E8B\\u4EF6\\u90FD\\u53EF\\u4EE5\\u59D4\\u6258\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u4E0D\\u4F1A\\u5192\\u6CE1\\u3002 \\u4E0D\\u5192\\u6CE1\\u7684\\u4E8B\\u4EF6\\u5305\\u62EC\\uFF1A\",(0,e.jsx)(n.code,{children:\"focus\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"blur\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"scroll\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"mouseenter\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"mouseleave\"}),\"\\u3001\",(0,e.jsx)(n.code,{children:\"resize\"}),\" \\u7B49\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E8B\\u4EF6\\u5F00\\u9500\\uFF1A\"}),\" \\u867D\\u7136\\u4E8B\\u4EF6\\u59D4\\u6258\\u901A\\u5E38\\u66F4\\u6709\\u6548\\uFF0C\\u4F46\\u9700\\u8981\\u5728\\u6839\\u4E8B\\u4EF6\\u4FA6\\u542C\\u5668\\u4E2D\\u7F16\\u5199\\u590D\\u6742\\u7684\\u903B\\u8F91\\u6765\\u8BC6\\u522B\\u89E6\\u53D1\\u5143\\u7D20\\u5E76\\u505A\\u51FA\\u9002\\u5F53\\u7684\\u54CD\\u5E94\\u3002 \\u5982\\u679C\\u7BA1\\u7406\\u4E0D\\u5F53\\uFF0C\\u8FD9\\u53EF\\u80FD\\u4F1A\\u5F15\\u5165\\u5F00\\u9500\\uFF0C\\u5E76\\u4E14\\u53EF\\u80FD\\u66F4\\u590D\\u6742\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"JavaScript \\u6846\\u67B6\\u4E2D\\u7684\\u4E8B\\u4EF6\\u59D4\\u6258\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728 \",(0,e.jsx)(n.a,{href:\"https://react.dev/\",children:\"React\"}),\" \\u4E2D\\uFF0C\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\u9644\\u52A0\\u5230 React \\u6839\\u7684 DOM \\u5BB9\\u5668\\u4E2D\\uFF0CReact \\u6811\\u88AB\\u6E32\\u67D3\\u5230\\u8BE5\\u5BB9\\u5668\\u4E2D\\u3002 \\u5373\\u4F7F\\u5C06 \",(0,e.jsx)(n.code,{children:\"onClick\"}),\" \\u6DFB\\u52A0\\u5230\\u5B50\\u5143\\u7D20\\uFF0C\\u5B9E\\u9645\\u7684\\u4E8B\\u4EF6\\u4FA6\\u542C\\u5668\\u4E5F\\u4F1A\\u9644\\u52A0\\u5230\\u6839 DOM \\u8282\\u70B9\\uFF0C\\u5229\\u7528\\u4E8B\\u4EF6\\u59D4\\u6258\\u6765\\u4F18\\u5316\\u4E8B\\u4EF6\\u5904\\u7406\\u5E76\\u63D0\\u9AD8\\u6027\\u80FD\\u3002\"]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5F53\\u4E8B\\u4EF6\\u53D1\\u751F\\u65F6\\uFF0CReact \\u7684\\u4E8B\\u4EF6\\u4FA6\\u542C\\u5668\\u4F1A\\u6355\\u83B7\\u5B83\\uFF0C\\u5E76\\u6839\\u636E\\u5176\\u5185\\u90E8\\u7C3F\\u8BB0\\u786E\\u5B9A\\u54EA\\u4E2A React \\u7EC4\\u4EF6\\u5448\\u73B0\\u4E86\\u76EE\\u6807\\u5143\\u7D20\\u3002 \\u7136\\u540E\\uFF0CReact \\u901A\\u8FC7\\u4F7F\\u7528\\u5408\\u6210\\u4E8B\\u4EF6\\u5BF9\\u8C61\\u8C03\\u7528\\u5904\\u7406\\u7A0B\\u5E8F\\u51FD\\u6570\\uFF0C\\u5C06\\u4E8B\\u4EF6\\u5206\\u6D3E\\u7ED9\\u76F8\\u5E94\\u7684\\u7EC4\\u4EF6\\u7684\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\u3002 \\u6B64\\u5408\\u6210\\u4E8B\\u4EF6\\u5BF9\\u8C61\\u5305\\u88C5\\u4E86\\u672C\\u673A\\u6D4F\\u89C8\\u5668\\u4E8B\\u4EF6\\uFF0C\\u63D0\\u4F9B\\u4E86\\u8DE8\\u4E0D\\u540C\\u6D4F\\u89C8\\u5668\\u7684\\u4E00\\u81F4\\u63A5\\u53E3\\uFF0C\\u5E76\\u6355\\u83B7\\u4E86\\u6709\\u5173\\u4E8B\\u4EF6\\u7684\\u4FE1\\u606F\\u3002\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u901A\\u8FC7\\u4F7F\\u7528\\u4E8B\\u4EF6\\u59D4\\u6258\\uFF0CReact \\u907F\\u514D\\u5C06\\u5355\\u4E2A\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\u9644\\u52A0\\u5230\\u6BCF\\u4E2A\\u7EC4\\u4EF6\\u5B9E\\u4F8B\\uFF0C\\u8FD9\\u5C06\\u4EA7\\u751F\\u5DE8\\u5927\\u7684\\u5F00\\u9500\\uFF0C\\u5C24\\u5176\\u5BF9\\u4E8E\\u5927\\u578B\\u7EC4\\u4EF6\\u6811\\u3002 \\u76F8\\u53CD\\uFF0CReact \\u5229\\u7528\\u6D4F\\u89C8\\u5668\\u7684\\u672C\\u673A\\u4E8B\\u4EF6\\u5192\\u6CE1\\u673A\\u5236\\u6765\\u6355\\u83B7\\u6839\\u5904\\u7684\\u4E8B\\u4EF6\\u5E76\\u5C06\\u5B83\\u4EEC\\u5206\\u53D1\\u5230\\u76F8\\u5E94\\u7684\\u7EC4\\u4EF6\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Events#event_delegation\",children:\"MDN Web Docs on Event Delegation\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/event-delegation\",children:\"JavaScript.info - Event Delegation\"})}),`\n`]})]})}function D(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(a,t)})):a(t)}var M=D;return B(x);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-hoisting/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-hoisting/locales/en-US.json
index 0864c281e..f48b5f1f8 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-hoisting/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-hoisting/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain the concept of \"hoisting\" in JavaScript",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/explain-hoisting/en-US.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var t=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var b=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),v=(i,e)=>{for(var r in e)t(i,r,{get:e[r],enumerable:!0})},a=(i,e,r,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of f(e))!g.call(i,o)&&o!==r&&t(i,o,{get:()=>e[o],enumerable:!(c=u(e,o))||c.enumerable});return i};var m=(i,e,r)=>(r=i!=null?h(p(i)):{},a(e||!i||!i.__esModule?t(r,\"default\",{value:i,enumerable:!0}):r,i)),w=i=>a(t({},\"__esModule\",{value:!0}),i);var l=b((j,d)=>{d.exports=_jsx_runtime});var R={};v(R,{default:()=>x,frontmatter:()=>y});var n=m(l()),y={title:'Explain the concept of \"hoisting\" in JavaScript'};function s(i){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",strong:\"strong\",code:\"code\",table:\"table\",thead:\"thead\",tr:\"tr\",th:\"th\",tbody:\"tbody\",td:\"td\",hr:\"hr\",h3:\"h3\",pre:\"pre\",a:\"a\",blockquote:\"blockquote\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:'Hoisting is a JavaScript mechanism where variable and function declarations are moved (\"hoisted\") to the top of their containing scope during the compile phase.'}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Variable declarations (\",(0,n.jsx)(e.code,{children:\"var\"}),\")\"]}),\": Declarations are hoisted, but not initializations. The value of the variable is \",(0,n.jsx)(e.code,{children:\"undefined\"}),\" if accessed before initialization.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Variable declarations (\",(0,n.jsx)(e.code,{children:\"let\"}),\" and \",(0,n.jsx)(e.code,{children:\"const\"}),\")\"]}),\": Declarations are hoisted, but not initialized. Accessing them results in \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\" until the actual declaration is encountered.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Function expressions (\",(0,n.jsx)(e.code,{children:\"var\"}),\")\"]}),\": Declarations are hoisted, but not initializations. The value of the variable is \",(0,n.jsx)(e.code,{children:\"undefined\"}),\" if accessed before initialization.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Function declarations (\",(0,n.jsx)(e.code,{children:\"function\"}),\")\"]}),\": Both declaration and definition are fully hoisted.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Class declarations (\",(0,n.jsx)(e.code,{children:\"class\"}),\")\"]}),\": Declarations are hoisted, but not initialized. Accessing them results in \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\" until the actual declaration is encountered.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Import declarations (\",(0,n.jsx)(e.code,{children:\"import\"}),\")\"]}),\": Declarations are hoisted, and side effects of importing the module are executed before the rest of the code.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"The following behavior summarizes the result of accessing the variables before they are declared.\"}),`\n`,(0,n.jsxs)(e.table,{children:[(0,n.jsx)(e.thead,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.th,{children:\"Declaration\"}),(0,n.jsx)(e.th,{children:\"Accessing before declaration\"})]})}),(0,n.jsxs)(e.tbody,{children:[(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"var foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"undefined\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"let foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"const foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"class Foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"var foo = function() { ... }\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"undefined\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"function foo() { ... }\"})}),(0,n.jsx)(e.td,{children:\"Normal\"})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"import\"})}),(0,n.jsx)(e.td,{children:\"Normal\"})]})]})]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Hoisting\"}),`\n`,(0,n.jsx)(e.p,{children:\"Hoisting is a term used to explain the behavior of variable declarations in JavaScript code.\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Variables declared or initialized with the \",(0,n.jsx)(e.code,{children:\"var\"}),' keyword will have their declaration \"moved\" up to the top of their containing scope during compilation, which we refer to as hoisting.']}),`\n`,(0,n.jsx)(e.p,{children:'Only the declaration is hoisted, the initialization/assignment (if there is one), will stay where it is. Note that the declaration is not actually moved \\u2013 the JavaScript engine parses the declarations during compilation and becomes aware of variables and their scopes, but it is easier to understand this behavior by visualizing the declarations as being \"hoisted\" to the top of their scope.'}),`\n`,(0,n.jsx)(e.p,{children:\"Let's explain with a few code samples. Note that the code for these examples should be executed within a module scope instead of being entered line by line into a REPL like the browser console.\"}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Hoisting of variables declared using \",(0,n.jsx)(e.code,{children:\"var\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Hoisting is seen in action here as even though \",(0,n.jsx)(e.code,{children:\"foo\"}),\" is declared and initialized after the first \",(0,n.jsx)(e.code,{children:\"console.log()\"}),\", the first \",(0,n.jsx)(e.code,{children:\"console.log()\"}),\" prints the value of \",(0,n.jsx)(e.code,{children:\"foo\"}),\" as \",(0,n.jsx)(e.code,{children:\"undefined\"}),\".\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(foo); // undefined\nvar foo = 1;\nconsole.log(foo); // 1\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"You can visualize the code as:\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`var foo;\nconsole.log(foo); // undefined\nfoo = 1;\nconsole.log(foo); // 1\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Hoisting of variables declared using \",(0,n.jsx)(e.code,{children:\"let\"}),\", \",(0,n.jsx)(e.code,{children:\"const\"}),\", and \",(0,n.jsx)(e.code,{children:\"class\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Variables declared via \",(0,n.jsx)(e.code,{children:\"let\"}),\", \",(0,n.jsx)(e.code,{children:\"const\"}),\", and \",(0,n.jsx)(e.code,{children:\"class\"}),\" are hoisted as well. However, unlike \",(0,n.jsx)(e.code,{children:\"var\"}),\" and \",(0,n.jsx)(e.code,{children:\"function\"}),\", they are not initialized and accessing them before the declaration will result in a \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),' exception. The variable is in a \"temporal dead zone\" from the start of the block until the declaration is processed.']}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`y; // ReferenceError: Cannot access 'y' before initialization\nlet y = 'local';\n`})}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`z; // ReferenceError: Cannot access 'z' before initialization\nconst z = 'local';\n`})}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`Foo; // ReferenceError: Cannot access 'Foo' before initialization\n\nclass Foo {\n constructor() {}\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Hoisting of function expressions\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Function expressions are functions written in the form of variable declarations. Since they are also declared using \",(0,n.jsx)(e.code,{children:\"var\"}),\", only the variable declaration is hoisted.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(bar); // undefined\nbar(); // Uncaught TypeError: bar is not a function\n\nvar bar = function () {\n console.log('BARRRR');\n};\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Hoisting of function declarations\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Function declarations use the \",(0,n.jsx)(e.code,{children:\"function\"}),\" keyword. Unlike function expressions, function declarations have both the declaration and definition hoisted, thus they can be called even before they are declared.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(foo); // [Function: foo]\nfoo(); // 'FOOOOO'\n\nfunction foo() {\n console.log('FOOOOO');\n}\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"The same applies to generators (\",(0,n.jsx)(e.code,{children:\"function*\"}),\"), async functions (\",(0,n.jsx)(e.code,{children:\"async function\"}),\"), and async function generators (\",(0,n.jsx)(e.code,{children:\"async function*\"}),\").\"]}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Hoisting of \",(0,n.jsx)(e.code,{children:\"import\"}),\" statements\"]}),`\n`,(0,n.jsx)(e.p,{children:\"Import declarations are hoisted. The identifiers the imports introduce are available in the entire module scope, and their side effects are produced before the rest of the module's code runs.\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`foo.doSomething(); // Works normally.\n\nimport foo from './modules/foo';\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Under the hood\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In reality, JavaScript creates all variables in the current scope before it even tries to execute the code. Variables created using \",(0,n.jsx)(e.code,{children:\"var\"}),\" keyword will have the value of \",(0,n.jsx)(e.code,{children:\"undefined\"}),\" where variables created using \",(0,n.jsx)(e.code,{children:\"let\"}),\" and \",(0,n.jsx)(e.code,{children:\"const\"}),\" keywords will be marked as \",(0,n.jsx)(e.code,{children:\"
\"}),\". Thus, accessing them will cause a \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\" preventing you to access them before initialization.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"In ECMAScript specifications \",(0,n.jsx)(e.code,{children:\"let\"}),\" and \",(0,n.jsx)(e.code,{children:\"const\"}),\" declarations are \",(0,n.jsx)(e.a,{href:\"https://tc39.es/ecma262/#sec-let-and-const-declarations\",children:\"explained as below\"}),\":\"]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsx)(e.p,{children:\"The variables are created when their containing Environment Record is instantiated but may not be accessed in any way until the variable's LexicalBinding is evaluated.\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"However, this statement is \",(0,n.jsxs)(e.a,{href:\"https://tc39.es/ecma262/#sec-variable-statement\",children:[\"a little different for the \",(0,n.jsx)(e.code,{children:\"var\"}),\" keyword\"]}),\":\"]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsxs)(e.p,{children:[\"Var variables are created when their containing Environment Record is instantiated and are initialized to \",(0,n.jsx)(e.code,{children:\"undefined\"}),\" when created.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Modern practices\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In practice, modern code bases avoid using \",(0,n.jsx)(e.code,{children:\"var\"}),\" and use \",(0,n.jsx)(e.code,{children:\"let\"}),\" and \",(0,n.jsx)(e.code,{children:\"const\"}),\" exclusively. It is recommended to declare and initialize your variables and import statements at the top of the containing scope/module to eliminate the mental overhead of tracking when a variable can be used.\"]}),`\n`,(0,n.jsx)(e.p,{children:\"ESLint is a static code analyzer that can find violations of such cases with the following rules:\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"https://eslint.org/docs/latest/rules/no-use-before-define\",children:(0,n.jsx)(e.code,{children:\"no-use-before-define\"})}),\": This rule will warn when it encounters a reference to an identifier that has not yet been declared.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"https://eslint.org/docs/latest/rules/no-undef\",children:(0,n.jsx)(e.code,{children:\"no-undef\"})}),\": This rule will warn when it encounters a reference to an identifier that has not yet been declared.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Glossary/Hoisting\",children:\"Hoisting | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://dev.to/lydiahallie/javascript-visualized-hoisting-478h\",children:\"JavaScript Visualized: Hoisting\"})}),`\n`]})]})}function z(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(s,i)})):s(i)}var x=z;return w(R);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var t=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var b=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),v=(i,e)=>{for(var r in e)t(i,r,{get:e[r],enumerable:!0})},a=(i,e,r,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of f(e))!g.call(i,o)&&o!==r&&t(i,o,{get:()=>e[o],enumerable:!(c=u(e,o))||c.enumerable});return i};var m=(i,e,r)=>(r=i!=null?h(p(i)):{},a(e||!i||!i.__esModule?t(r,\"default\",{value:i,enumerable:!0}):r,i)),w=i=>a(t({},\"__esModule\",{value:!0}),i);var l=b((j,d)=>{d.exports=_jsx_runtime});var R={};v(R,{default:()=>x,frontmatter:()=>y});var n=m(l()),y={title:'Explain the concept of \"hoisting\" in JavaScript'};function s(i){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",strong:\"strong\",code:\"code\",table:\"table\",thead:\"thead\",tr:\"tr\",th:\"th\",tbody:\"tbody\",td:\"td\",hr:\"hr\",h3:\"h3\",pre:\"pre\",a:\"a\",blockquote:\"blockquote\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:'Hoisting is a JavaScript mechanism where variable and function declarations are moved (\"hoisted\") to the top of their containing scope during the compile phase.'}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Variable declarations (\",(0,n.jsx)(e.code,{children:\"var\"}),\")\"]}),\": Declarations are hoisted, but not initializations. The value of the variable is \",(0,n.jsx)(e.code,{children:\"undefined\"}),\" if accessed before initialization.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Variable declarations (\",(0,n.jsx)(e.code,{children:\"let\"}),\" and \",(0,n.jsx)(e.code,{children:\"const\"}),\")\"]}),\": Declarations are hoisted, but not initialized. Accessing them results in \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\" until the actual declaration is encountered.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Function expressions (\",(0,n.jsx)(e.code,{children:\"var\"}),\")\"]}),\": Declarations are hoisted, but not initializations. The value of the variable is \",(0,n.jsx)(e.code,{children:\"undefined\"}),\" if accessed before initialization.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Function declarations (\",(0,n.jsx)(e.code,{children:\"function\"}),\")\"]}),\": Both declaration and definition are fully hoisted.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Class declarations (\",(0,n.jsx)(e.code,{children:\"class\"}),\")\"]}),\": Declarations are hoisted, but not initialized. Accessing them results in \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\" until the actual declaration is encountered.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Import declarations (\",(0,n.jsx)(e.code,{children:\"import\"}),\")\"]}),\": Declarations are hoisted, and side effects of importing the module are executed before the rest of the code.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"The following behavior summarizes the result of accessing the variables before they are declared.\"}),`\n`,(0,n.jsxs)(e.table,{children:[(0,n.jsx)(e.thead,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.th,{children:\"Declaration\"}),(0,n.jsx)(e.th,{children:\"Accessing before declaration\"})]})}),(0,n.jsxs)(e.tbody,{children:[(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"var foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"undefined\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"let foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"const foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"class Foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"var foo = function() { ... }\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"undefined\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"function foo() { ... }\"})}),(0,n.jsx)(e.td,{children:\"Normal\"})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"import\"})}),(0,n.jsx)(e.td,{children:\"Normal\"})]})]})]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Hoisting\"}),`\n`,(0,n.jsx)(e.p,{children:\"Hoisting is a term used to explain the behavior of variable declarations in JavaScript code.\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Variables declared or initialized with the \",(0,n.jsx)(e.code,{children:\"var\"}),' keyword will have their declaration \"moved\" up to the top of their containing scope during compilation, which we refer to as hoisting.']}),`\n`,(0,n.jsx)(e.p,{children:'Only the declaration is hoisted, the initialization/assignment (if there is one), will stay where it is. Note that the declaration is not actually moved \\u2013 the JavaScript engine parses the declarations during compilation and becomes aware of variables and their scopes, but it is easier to understand this behavior by visualizing the declarations as being \"hoisted\" to the top of their scope.'}),`\n`,(0,n.jsx)(e.p,{children:\"Let's explain with a few code samples. Note that the code for these examples should be executed within a module scope instead of being entered line by line into a REPL like the browser console.\"}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Hoisting of variables declared using \",(0,n.jsx)(e.code,{children:\"var\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Hoisting is seen in action here as even though \",(0,n.jsx)(e.code,{children:\"foo\"}),\" is declared and initialized after the first \",(0,n.jsx)(e.code,{children:\"console.log()\"}),\", the first \",(0,n.jsx)(e.code,{children:\"console.log()\"}),\" prints the value of \",(0,n.jsx)(e.code,{children:\"foo\"}),\" as \",(0,n.jsx)(e.code,{children:\"undefined\"}),\".\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(foo); // undefined\nvar foo = 1;\nconsole.log(foo); // 1\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"You can visualize the code as:\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`var foo;\nconsole.log(foo); // undefined\nfoo = 1;\nconsole.log(foo); // 1\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Hoisting of variables declared using \",(0,n.jsx)(e.code,{children:\"let\"}),\", \",(0,n.jsx)(e.code,{children:\"const\"}),\", and \",(0,n.jsx)(e.code,{children:\"class\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Variables declared via \",(0,n.jsx)(e.code,{children:\"let\"}),\", \",(0,n.jsx)(e.code,{children:\"const\"}),\", and \",(0,n.jsx)(e.code,{children:\"class\"}),\" are hoisted as well. However, unlike \",(0,n.jsx)(e.code,{children:\"var\"}),\" and \",(0,n.jsx)(e.code,{children:\"function\"}),\", they are not initialized and accessing them before the declaration will result in a \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),' exception. The variable is in a \"temporal dead zone\" from the start of the block until the declaration is processed.']}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`y; // ReferenceError: Cannot access 'y' before initialization\nlet y = 'local';\n`})}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`z; // ReferenceError: Cannot access 'z' before initialization\nconst z = 'local';\n`})}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`Foo; // ReferenceError: Cannot access 'Foo' before initialization\n\nclass Foo {\n constructor() {}\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Hoisting of function expressions\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Function expressions are functions written in the form of variable declarations. Since they are also declared using \",(0,n.jsx)(e.code,{children:\"var\"}),\", only the variable declaration is hoisted.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(bar); // undefined\nbar(); // Uncaught TypeError: bar is not a function\n\nvar bar = function () {\n console.log('BARRRR');\n};\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Hoisting of function declarations\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Function declarations use the \",(0,n.jsx)(e.code,{children:\"function\"}),\" keyword. Unlike function expressions, function declarations have both the declaration and definition hoisted, thus they can be called even before they are declared.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(foo); // [Function: foo]\nfoo(); // 'FOOOOO'\n\nfunction foo() {\n console.log('FOOOOO');\n}\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"The same applies to generators (\",(0,n.jsx)(e.code,{children:\"function*\"}),\"), async functions (\",(0,n.jsx)(e.code,{children:\"async function\"}),\"), and async function generators (\",(0,n.jsx)(e.code,{children:\"async function*\"}),\").\"]}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Hoisting of \",(0,n.jsx)(e.code,{children:\"import\"}),\" statements\"]}),`\n`,(0,n.jsx)(e.p,{children:\"Import declarations are hoisted. The identifiers the imports introduce are available in the entire module scope, and their side effects are produced before the rest of the module's code runs.\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`foo.doSomething(); // Works normally.\n\nimport foo from './modules/foo';\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Under the hood\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In reality, JavaScript creates all variables in the current scope before it even tries to execute the code. Variables created using \",(0,n.jsx)(e.code,{children:\"var\"}),\" keyword will have the value of \",(0,n.jsx)(e.code,{children:\"undefined\"}),\" where variables created using \",(0,n.jsx)(e.code,{children:\"let\"}),\" and \",(0,n.jsx)(e.code,{children:\"const\"}),\" keywords will be marked as \",(0,n.jsx)(e.code,{children:\"\"}),\". Thus, accessing them will cause a \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\" preventing you to access them before initialization.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"In ECMAScript specifications \",(0,n.jsx)(e.code,{children:\"let\"}),\" and \",(0,n.jsx)(e.code,{children:\"const\"}),\" declarations are \",(0,n.jsx)(e.a,{href:\"https://tc39.es/ecma262/#sec-let-and-const-declarations\",children:\"explained as below\"}),\":\"]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsx)(e.p,{children:\"The variables are created when their containing Environment Record is instantiated but may not be accessed in any way until the variable's LexicalBinding is evaluated.\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"However, this statement is \",(0,n.jsxs)(e.a,{href:\"https://tc39.es/ecma262/#sec-variable-statement\",children:[\"a little different for the \",(0,n.jsx)(e.code,{children:\"var\"}),\" keyword\"]}),\":\"]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsxs)(e.p,{children:[\"Var variables are created when their containing Environment Record is instantiated and are initialized to \",(0,n.jsx)(e.code,{children:\"undefined\"}),\" when created.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Modern practices\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In practice, modern code bases avoid using \",(0,n.jsx)(e.code,{children:\"var\"}),\" and use \",(0,n.jsx)(e.code,{children:\"let\"}),\" and \",(0,n.jsx)(e.code,{children:\"const\"}),\" exclusively. It is recommended to declare and initialize your variables and import statements at the top of the containing scope/module to eliminate the mental overhead of tracking when a variable can be used.\"]}),`\n`,(0,n.jsx)(e.p,{children:\"ESLint is a static code analyzer that can find violations of such cases with the following rules:\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"https://eslint.org/docs/latest/rules/no-use-before-define\",children:(0,n.jsx)(e.code,{children:\"no-use-before-define\"})}),\": This rule will warn when it encounters a reference to an identifier that has not yet been declared.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"https://eslint.org/docs/latest/rules/no-undef\",children:(0,n.jsx)(e.code,{children:\"no-undef\"})}),\": This rule will warn when it encounters a reference to an identifier that has not yet been declared.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Glossary/Hoisting\",children:\"Hoisting | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://www.freecodecamp.org/news/what-is-hoisting-in-javascript\",children:\"What is Hoisting in JavaScript?\"})}),`\n`]})]})}function z(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(s,i)})):s(i)}var x=z;return w(R);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-hoisting/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-hoisting/locales/zh-CN.json
index 71b7e4c93..ec996256d 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-hoisting/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-hoisting/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释 JavaScript 中的“hoisting”(变量提升)概念",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/explain-hoisting/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var v=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports),m=(c,e)=>{for(var r in e)i(c,r,{get:e[r],enumerable:!0})},o=(c,e,r,l)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let d of u(e))!g.call(c,d)&&d!==r&&i(c,d,{get:()=>e[d],enumerable:!(l=f(e,d))||l.enumerable});return c};var b=(c,e,r)=>(r=c!=null?s(p(c)):{},o(e||!c||!c.__esModule?i(r,\"default\",{value:c,enumerable:!0}):r,c)),R=c=>o(i({},\"__esModule\",{value:!0}),c);var t=v((z,h)=>{h.exports=_jsx_runtime});var O={};m(O,{default:()=>y,frontmatter:()=>j});var n=b(t()),j={title:\"\\u89E3\\u91CA JavaScript \\u4E2D\\u7684\\u201Choisting\\u201D\\uFF08\\u53D8\\u91CF\\u63D0\\u5347\\uFF09\\u6982\\u5FF5\"};function a(c){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",strong:\"strong\",code:\"code\",table:\"table\",thead:\"thead\",tr:\"tr\",th:\"th\",tbody:\"tbody\",td:\"td\",hr:\"hr\",h3:\"h3\",pre:\"pre\",a:\"a\",blockquote:\"blockquote\"},c.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"Hoisting\\uFF08\\u53D8\\u91CF\\u63D0\\u5347\\uFF09\\u662F\\u4E00\\u79CD JavaScript \\u673A\\u5236\\uFF0C\\u5728\\u7F16\\u8BD1\\u9636\\u6BB5\\uFF0C\\u53D8\\u91CF\\u548C\\u51FD\\u6570\\u58F0\\u660E\\u4F1A\\u88AB\\u201C\\u63D0\\u5347\\u201D\\u5230\\u5176\\u5305\\u542B\\u4F5C\\u7528\\u57DF\\u7684\\u9876\\u90E8\\u3002\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u53D8\\u91CF\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"var\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u4F46\\u672A\\u521D\\u59CB\\u5316\\u3002\\u5982\\u679C\\u5728\\u4F7F\\u7528\\u524D\\u8BBF\\u95EE\\u53D8\\u91CF\\uFF0C\\u5219\\u53D8\\u91CF\\u7684\\u503C\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u53D8\\u91CF\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"let\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"const\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u4F46\\u672A\\u521D\\u59CB\\u5316\\u3002\\u8BBF\\u95EE\\u5B83\\u4EEC\\u4F1A\\u5BFC\\u81F4 \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\"\\uFF0C\\u76F4\\u5230\\u9047\\u5230\\u5B9E\\u9645\\u7684\\u58F0\\u660E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u51FD\\u6570\\u8868\\u8FBE\\u5F0F (\",(0,n.jsx)(e.code,{children:\"var\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u4F46\\u672A\\u521D\\u59CB\\u5316\\u3002\\u5982\\u679C\\u5728\\u4F7F\\u7528\\u524D\\u8BBF\\u95EE\\u53D8\\u91CF\\uFF0C\\u5219\\u53D8\\u91CF\\u7684\\u503C\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u51FD\\u6570\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"function\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u548C\\u5B9A\\u4E49\\u90FD\\u88AB\\u5B8C\\u5168\\u63D0\\u5347\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u7C7B\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"class\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u4F46\\u672A\\u521D\\u59CB\\u5316\\u3002\\u8BBF\\u95EE\\u5B83\\u4EEC\\u4F1A\\u5BFC\\u81F4 \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\"\\uFF0C\\u76F4\\u5230\\u9047\\u5230\\u5B9E\\u9645\\u7684\\u58F0\\u660E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u5BFC\\u5165\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"import\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u5E76\\u4E14\\u5728\\u6267\\u884C\\u5176\\u4F59\\u4EE3\\u7801\\u4E4B\\u524D\\uFF0C\\u4F1A\\u6267\\u884C\\u5BFC\\u5165\\u6A21\\u5757\\u7684\\u526F\\u4F5C\\u7528\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4EE5\\u4E0B\\u884C\\u4E3A\\u603B\\u7ED3\\u4E86\\u5728\\u58F0\\u660E\\u53D8\\u91CF\\u4E4B\\u524D\\u8BBF\\u95EE\\u53D8\\u91CF\\u7684\\u7ED3\\u679C\\u3002\"}),`\n`,(0,n.jsxs)(e.table,{children:[(0,n.jsx)(e.thead,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.th,{children:\"\\u58F0\\u660E\"}),(0,n.jsx)(e.th,{children:\"\\u5728\\u58F0\\u660E\\u4E4B\\u524D\\u8BBF\\u95EE\"})]})}),(0,n.jsxs)(e.tbody,{children:[(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"var foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"undefined\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"let foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"const foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"class Foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"var foo = function() { ... }\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"undefined\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"function foo() { ... }\"})}),(0,n.jsx)(e.td,{children:\"\\u6B63\\u5E38\"})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"import\"})}),(0,n.jsx)(e.td,{children:\"\\u6B63\\u5E38\"})]})]})]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Hoisting\\uFF08\\u53D8\\u91CF\\u63D0\\u5347\\uFF09\"}),`\n`,(0,n.jsx)(e.p,{children:\"Hoisting\\uFF08\\u53D8\\u91CF\\u63D0\\u5347\\uFF09\\u662F\\u4E00\\u4E2A\\u672F\\u8BED\\uFF0C\\u7528\\u4E8E\\u89E3\\u91CA JavaScript \\u4EE3\\u7801\\u4E2D\\u53D8\\u91CF\\u58F0\\u660E\\u7684\\u884C\\u4E3A\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u5173\\u952E\\u5B57\\u58F0\\u660E\\u6216\\u521D\\u59CB\\u5316\\u7684\\u53D8\\u91CF\\u5C06\\u5728\\u7F16\\u8BD1\\u671F\\u95F4\\u5C06\\u5176\\u58F0\\u660E\\u201C\\u79FB\\u52A8\\u201D\\u5230\\u5176\\u5305\\u542B\\u4F5C\\u7528\\u57DF\\u7684\\u9876\\u90E8\\uFF0C\\u6211\\u4EEC\\u5C06\\u5176\\u79F0\\u4E3A\\u53D8\\u91CF\\u63D0\\u5347\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u53EA\\u6709\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u521D\\u59CB\\u5316/\\u8D4B\\u503C\\uFF08\\u5982\\u679C\\u5B58\\u5728\\uFF09\\u5C06\\u4FDD\\u7559\\u5728\\u539F\\u6765\\u7684\\u4F4D\\u7F6E\\u3002\\u8BF7\\u6CE8\\u610F\\uFF0C\\u58F0\\u660E\\u5B9E\\u9645\\u4E0A\\u5E76\\u6CA1\\u6709\\u79FB\\u52A8\\u2014\\u2014JavaScript \\u5F15\\u64CE\\u5728\\u7F16\\u8BD1\\u671F\\u95F4\\u4F1A\\u89E3\\u6790\\u58F0\\u660E\\uFF0C\\u5E76\\u4E86\\u89E3\\u53D8\\u91CF\\u53CA\\u5176\\u4F5C\\u7528\\u57DF\\uFF0C\\u4F46\\u662F\\u901A\\u8FC7\\u5C06\\u58F0\\u660E\\u53EF\\u89C6\\u5316\\u4E3A\\u201C\\u63D0\\u5347\\u201D\\u5230\\u5176\\u4F5C\\u7528\\u57DF\\u7684\\u9876\\u90E8\\uFF0C\\u66F4\\u5BB9\\u6613\\u7406\\u89E3\\u8FD9\\u79CD\\u884C\\u4E3A\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u7528\\u51E0\\u4E2A\\u4EE3\\u7801\\u793A\\u4F8B\\u6765\\u89E3\\u91CA\\u3002\\u8BF7\\u6CE8\\u610F\\uFF0C\\u8FD9\\u4E9B\\u793A\\u4F8B\\u7684\\u4EE3\\u7801\\u5E94\\u8BE5\\u5728\\u6A21\\u5757\\u4F5C\\u7528\\u57DF\\u5185\\u6267\\u884C\\uFF0C\\u800C\\u4E0D\\u662F\\u50CF\\u6D4F\\u89C8\\u5668\\u63A7\\u5236\\u53F0\\u90A3\\u6837\\u9010\\u884C\\u8F93\\u5165\\u5230 REPL \\u4E2D\\u3002\"}),`\n`,(0,n.jsxs)(e.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u58F0\\u660E\\u7684\\u53D8\\u91CF\\u7684\\u53D8\\u91CF\\u63D0\\u5347\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u8FD9\\u91CC\\u53EF\\u4EE5\\u770B\\u5230\\u53D8\\u91CF\\u63D0\\u5347\\u7684\\u5B9E\\u9645\\u6548\\u679C\\uFF0C\\u5373\\u4F7F\\u5728\\u7B2C\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"console.log()\"}),\" \\u4E4B\\u540E\\u624D\\u58F0\\u660E\\u548C\\u521D\\u59CB\\u5316 \",(0,n.jsx)(e.code,{children:\"foo\"}),\"\\uFF0C\\u7B2C\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"console.log()\"}),\" \\u4E5F\\u4F1A\\u5C06 \",(0,n.jsx)(e.code,{children:\"foo\"}),\" \\u7684\\u503C\\u6253\\u5370\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(foo); // undefined\nvar foo = 1;\nconsole.log(foo); // 1\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"\\u60A8\\u53EF\\u4EE5\\u5C06\\u4EE3\\u7801\\u53EF\\u89C6\\u5316\\u4E3A\\uFF1A\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`var foo;\nconsole.log(foo); // undefined\nfoo = 1;\nconsole.log(foo); // 1\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"let\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"const\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"class\"}),\" \\u58F0\\u660E\\u7684\\u53D8\\u91CF\\u7684\\u53D8\\u91CF\\u63D0\\u5347\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u901A\\u8FC7 \",(0,n.jsx)(e.code,{children:\"let\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"const\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"class\"}),\" \\u58F0\\u660E\\u7684\\u53D8\\u91CF\\u4E5F\\u4F1A\\u88AB\\u63D0\\u5347\\u3002\\u4F46\\u662F\\uFF0C\\u4E0E \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"function\"}),\" \\u4E0D\\u540C\\uFF0C\\u5B83\\u4EEC\\u6CA1\\u6709\\u88AB\\u521D\\u59CB\\u5316\\uFF0C\\u5728\\u58F0\\u660E\\u4E4B\\u524D\\u8BBF\\u95EE\\u5B83\\u4EEC\\u5C06\\u5BFC\\u81F4 \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\" \\u5F02\\u5E38\\u3002\\u8BE5\\u53D8\\u91CF\\u5904\\u4E8E\\u4E00\\u4E2A\\u201C\\u6682\\u65F6\\u6027\\u6B7B\\u533A\\u201D\\uFF0C\\u4ECE\\u5757\\u7684\\u5F00\\u59CB\\u5230\\u58F0\\u660E\\u88AB\\u5904\\u7406\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`y; // ReferenceError: Cannot access 'y' before initialization\nlet y = 'local';\n`})}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`z; // ReferenceError: Cannot access 'z' before initialization\nconst z = 'local';\n`})}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`Foo; // ReferenceError: Cannot access 'Foo' before initialization\n\nclass Foo {\n constructor() {}\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u51FD\\u6570\\u8868\\u8FBE\\u5F0F\\u7684\\u63D0\\u5347\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u51FD\\u6570\\u8868\\u8FBE\\u5F0F\\u662F\\u4EE5\\u53D8\\u91CF\\u58F0\\u660E\\u7684\\u5F62\\u5F0F\\u7F16\\u5199\\u7684\\u51FD\\u6570\\u3002\\u7531\\u4E8E\\u5B83\\u4EEC\\u4E5F\\u662F\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u58F0\\u660E\\u7684\\uFF0C\\u56E0\\u6B64\\u53EA\\u6709\\u53D8\\u91CF\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(bar); // undefined\nbar(); // Uncaught TypeError: bar is not a function\n\nvar bar = function () {\n console.log('BARRRR');\n};\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u51FD\\u6570\\u58F0\\u660E\\u7684\\u63D0\\u5347\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u51FD\\u6570\\u58F0\\u660E\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"function\"}),\" \\u5173\\u952E\\u5B57\\u3002\\u4E0E\\u51FD\\u6570\\u8868\\u8FBE\\u5F0F\\u4E0D\\u540C\\uFF0C\\u51FD\\u6570\\u58F0\\u660E\\u540C\\u65F6\\u63D0\\u5347\\u58F0\\u660E\\u548C\\u5B9A\\u4E49\\uFF0C\\u56E0\\u6B64\\u5373\\u4F7F\\u5728\\u58F0\\u660E\\u4E4B\\u524D\\u4E5F\\u53EF\\u4EE5\\u8C03\\u7528\\u5B83\\u4EEC\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(foo); // [Function: foo]\nfoo(); // 'FOOOOO'\n\nfunction foo() {\n console.log('FOOOOO');\n}\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u540C\\u6837\\u9002\\u7528\\u4E8E\\u751F\\u6210\\u5668 (\",(0,n.jsx)(e.code,{children:\"function*\"}),\")\\u3001\\u5F02\\u6B65\\u51FD\\u6570 (\",(0,n.jsx)(e.code,{children:\"async function\"}),\") \\u548C\\u5F02\\u6B65\\u51FD\\u6570\\u751F\\u6210\\u5668 (\",(0,n.jsx)(e.code,{children:\"async function*\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.h3,{children:[(0,n.jsx)(e.code,{children:\"import\"}),\" \\u8BED\\u53E5\\u7684\\u63D0\\u5347\"]}),`\n`,(0,n.jsx)(e.p,{children:\"Import \\u58F0\\u660E\\u88AB\\u63D0\\u5347\\u3002import \\u5F15\\u5165\\u7684\\u6807\\u8BC6\\u7B26\\u5728\\u6574\\u4E2A\\u6A21\\u5757\\u8303\\u56F4\\u5185\\u90FD\\u53EF\\u7528\\uFF0C\\u5E76\\u4E14\\u5B83\\u4EEC\\u4EA7\\u751F\\u7684\\u526F\\u4F5C\\u7528\\u5728\\u6A21\\u5757\\u7684\\u5176\\u4F59\\u4EE3\\u7801\\u8FD0\\u884C\\u4E4B\\u524D\\u4EA7\\u751F\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`foo.doSomething(); // Works normally.\n\nimport foo from './modules/foo';\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5E55\\u540E\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5B9E\\u9645\\u4E0A\\uFF0CJavaScript \\u5728\\u5C1D\\u8BD5\\u6267\\u884C\\u4EE3\\u7801\\u4E4B\\u524D\\uFF0C\\u4F1A\\u5728\\u5F53\\u524D\\u4F5C\\u7528\\u57DF\\u4E2D\\u521B\\u5EFA\\u6240\\u6709\\u53D8\\u91CF\\u3002\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u5173\\u952E\\u5B57\\u521B\\u5EFA\\u7684\\u53D8\\u91CF\\u7684\\u503C\\u5C06\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\uFF0C\\u800C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"let\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"const\"}),\" \\u5173\\u952E\\u5B57\\u521B\\u5EFA\\u7684\\u53D8\\u91CF\\u5C06\\u88AB\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"\"}),\"\\u3002\\u56E0\\u6B64\\uFF0C\\u5728\\u521D\\u59CB\\u5316\\u4E4B\\u524D\\u8BBF\\u95EE\\u5B83\\u4EEC\\u5C06\\u5BFC\\u81F4 \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\"\\uFF0C\\u4ECE\\u800C\\u963B\\u6B62\\u60A8\\u5728\\u521D\\u59CB\\u5316\\u4E4B\\u524D\\u8BBF\\u95EE\\u5B83\\u4EEC\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728 ECMAScript \\u89C4\\u8303\\u4E2D\\uFF0C\",(0,n.jsx)(e.code,{children:\"let\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"const\"}),\" \\u58F0\\u660E\",(0,n.jsx)(e.a,{href:\"https://tc39.es/ecma262/#sec-let-and-const-declarations\",children:\"\\u89E3\\u91CA\\u5982\\u4E0B\"}),\"\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsx)(e.p,{children:\"\\u5F53\\u5B83\\u4EEC\\u5305\\u542B\\u7684 Environment Record \\u88AB\\u5B9E\\u4F8B\\u5316\\u65F6\\uFF0C\\u53D8\\u91CF\\u88AB\\u521B\\u5EFA\\uFF0C\\u4F46\\u5728\\u53D8\\u91CF\\u7684 LexicalBinding \\u88AB\\u6C42\\u503C\\u4E4B\\u524D\\uFF0C\\u53EF\\u80FD\\u65E0\\u6CD5\\u4EE5\\u4EFB\\u4F55\\u65B9\\u5F0F\\u8BBF\\u95EE\\u5B83\\u4EEC\\u3002\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F46\\u662F\\uFF0C\\u5BF9\\u4E8E \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u5173\\u952E\\u5B57\\uFF0C\\u6B64\\u8BED\\u53E5\",(0,n.jsx)(e.a,{href:\"https://tc39.es/ecma262/#sec-variable-statement\",children:\"\\u7565\\u6709\\u4E0D\\u540C\"}),\"\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5F53\\u5B83\\u4EEC\\u5305\\u542B\\u7684 Environment Record \\u88AB\\u5B9E\\u4F8B\\u5316\\u65F6\\uFF0CVar \\u53D8\\u91CF\\u88AB\\u521B\\u5EFA\\uFF0C\\u5E76\\u5728\\u521B\\u5EFA\\u65F6\\u88AB\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u73B0\\u4EE3\\u5B9E\\u8DF5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u5B9E\\u8DF5\\u4E2D\\uFF0C\\u73B0\\u4EE3\\u4EE3\\u7801\\u5E93\\u907F\\u514D\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\"\\uFF0C\\u5E76\\u4E14\\u4EC5\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"let\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"const\"}),\"\\u3002\\u5EFA\\u8BAE\\u5728\\u5305\\u542B\\u8303\\u56F4/\\u6A21\\u5757\\u7684\\u9876\\u90E8\\u58F0\\u660E\\u548C\\u521D\\u59CB\\u5316\\u53D8\\u91CF\\u548C import \\u8BED\\u53E5\\uFF0C\\u4EE5\\u6D88\\u9664\\u8DDF\\u8E2A\\u4F55\\u65F6\\u53EF\\u4EE5\\u4F7F\\u7528\\u53D8\\u91CF\\u7684\\u5FC3\\u7406\\u8D1F\\u62C5\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"ESLint \\u662F\\u4E00\\u4E2A\\u9759\\u6001\\u4EE3\\u7801\\u5206\\u6790\\u5668\\uFF0C\\u53EF\\u4EE5\\u53D1\\u73B0\\u8FDD\\u53CD\\u6B64\\u7C7B\\u60C5\\u51B5\\uFF0C\\u4F7F\\u7528\\u4EE5\\u4E0B\\u89C4\\u5219\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"https://eslint.org/docs/latest/rules/no-use-before-define\",children:(0,n.jsx)(e.code,{children:\"no-use-before-define\"})}),\": \\u5F53\\u9047\\u5230\\u5BF9\\u5C1A\\u672A\\u58F0\\u660E\\u7684\\u6807\\u8BC6\\u7B26\\u7684\\u5F15\\u7528\\u65F6\\uFF0C\\u6B64\\u89C4\\u5219\\u5C06\\u53D1\\u51FA\\u8B66\\u544A\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"https://eslint.org/docs/latest/rules/no-undef\",children:(0,n.jsx)(e.code,{children:\"no-undef\"})}),\": \\u5F53\\u9047\\u5230\\u5BF9\\u5C1A\\u672A\\u58F0\\u660E\\u7684\\u6807\\u8BC6\\u7B26\\u7684\\u5F15\\u7528\\u65F6\\uFF0C\\u6B64\\u89C4\\u5219\\u5C06\\u53D1\\u51FA\\u8B66\\u544A\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/zh-CN/docs/Glossary/Hoisting\",children:\"Hoisting | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://dev.to/lydiahallie/javascript-visualized-hoisting-478h\",children:\"JavaScript Visualized: Hoisting\"})}),`\n`]})]})}function E(c={}){let{wrapper:e}=c.components||{};return e?(0,n.jsx)(e,Object.assign({},c,{children:(0,n.jsx)(a,c)})):a(c)}var y=E;return R(O);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var i=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(c,e)=>()=>(e||c((e={exports:{}}).exports,e),e.exports),v=(c,e)=>{for(var r in e)i(c,r,{get:e[r],enumerable:!0})},l=(c,e,r,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let d of u(e))!g.call(c,d)&&d!==r&&i(c,d,{get:()=>e[d],enumerable:!(o=f(e,d))||o.enumerable});return c};var b=(c,e,r)=>(r=c!=null?s(p(c)):{},l(e||!c||!c.__esModule?i(r,\"default\",{value:c,enumerable:!0}):r,c)),R=c=>l(i({},\"__esModule\",{value:!0}),c);var t=m((S,h)=>{h.exports=_jsx_runtime});var O={};v(O,{default:()=>y,frontmatter:()=>j});var n=b(t()),j={title:\"\\u89E3\\u91CA JavaScript \\u4E2D\\u7684\\u201Choisting\\u201D\\uFF08\\u53D8\\u91CF\\u63D0\\u5347\\uFF09\\u6982\\u5FF5\"};function a(c){let e=Object.assign({h2:\"h2\",p:\"p\",ul:\"ul\",li:\"li\",strong:\"strong\",code:\"code\",table:\"table\",thead:\"thead\",tr:\"tr\",th:\"th\",tbody:\"tbody\",td:\"td\",hr:\"hr\",h3:\"h3\",pre:\"pre\",a:\"a\",blockquote:\"blockquote\"},c.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"Hoisting\\uFF08\\u53D8\\u91CF\\u63D0\\u5347\\uFF09\\u662F\\u4E00\\u79CD JavaScript \\u673A\\u5236\\uFF0C\\u5728\\u7F16\\u8BD1\\u9636\\u6BB5\\uFF0C\\u53D8\\u91CF\\u548C\\u51FD\\u6570\\u58F0\\u660E\\u4F1A\\u88AB\\u201C\\u63D0\\u5347\\u201D\\u5230\\u5176\\u5305\\u542B\\u4F5C\\u7528\\u57DF\\u7684\\u9876\\u90E8\\u3002\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u53D8\\u91CF\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"var\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u4F46\\u672A\\u521D\\u59CB\\u5316\\u3002\\u5982\\u679C\\u5728\\u4F7F\\u7528\\u524D\\u8BBF\\u95EE\\u53D8\\u91CF\\uFF0C\\u5219\\u53D8\\u91CF\\u7684\\u503C\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u53D8\\u91CF\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"let\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"const\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u4F46\\u672A\\u521D\\u59CB\\u5316\\u3002\\u8BBF\\u95EE\\u5B83\\u4EEC\\u4F1A\\u5BFC\\u81F4 \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\"\\uFF0C\\u76F4\\u5230\\u9047\\u5230\\u5B9E\\u9645\\u7684\\u58F0\\u660E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u51FD\\u6570\\u8868\\u8FBE\\u5F0F (\",(0,n.jsx)(e.code,{children:\"var\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u4F46\\u672A\\u521D\\u59CB\\u5316\\u3002\\u5982\\u679C\\u5728\\u4F7F\\u7528\\u524D\\u8BBF\\u95EE\\u53D8\\u91CF\\uFF0C\\u5219\\u53D8\\u91CF\\u7684\\u503C\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u51FD\\u6570\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"function\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u548C\\u5B9A\\u4E49\\u90FD\\u88AB\\u5B8C\\u5168\\u63D0\\u5347\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u7C7B\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"class\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u4F46\\u672A\\u521D\\u59CB\\u5316\\u3002\\u8BBF\\u95EE\\u5B83\\u4EEC\\u4F1A\\u5BFC\\u81F4 \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\"\\uFF0C\\u76F4\\u5230\\u9047\\u5230\\u5B9E\\u9645\\u7684\\u58F0\\u660E\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"\\u5BFC\\u5165\\u58F0\\u660E (\",(0,n.jsx)(e.code,{children:\"import\"}),\")\"]}),\"\\uFF1A\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u5E76\\u4E14\\u5728\\u6267\\u884C\\u5176\\u4F59\\u4EE3\\u7801\\u4E4B\\u524D\\uFF0C\\u4F1A\\u6267\\u884C\\u5BFC\\u5165\\u6A21\\u5757\\u7684\\u526F\\u4F5C\\u7528\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4EE5\\u4E0B\\u884C\\u4E3A\\u603B\\u7ED3\\u4E86\\u5728\\u58F0\\u660E\\u53D8\\u91CF\\u4E4B\\u524D\\u8BBF\\u95EE\\u53D8\\u91CF\\u7684\\u7ED3\\u679C\\u3002\"}),`\n`,(0,n.jsxs)(e.table,{children:[(0,n.jsx)(e.thead,{children:(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.th,{children:\"\\u58F0\\u660E\"}),(0,n.jsx)(e.th,{children:\"\\u5728\\u58F0\\u660E\\u4E4B\\u524D\\u8BBF\\u95EE\"})]})}),(0,n.jsxs)(e.tbody,{children:[(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"var foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"undefined\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"let foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"const foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"class Foo\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"ReferenceError\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"var foo = function() { ... }\"})}),(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"undefined\"})})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"function foo() { ... }\"})}),(0,n.jsx)(e.td,{children:\"\\u6B63\\u5E38\"})]}),(0,n.jsxs)(e.tr,{children:[(0,n.jsx)(e.td,{children:(0,n.jsx)(e.code,{children:\"import\"})}),(0,n.jsx)(e.td,{children:\"\\u6B63\\u5E38\"})]})]})]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Hoisting\\uFF08\\u53D8\\u91CF\\u63D0\\u5347\\uFF09\"}),`\n`,(0,n.jsx)(e.p,{children:\"Hoisting\\uFF08\\u53D8\\u91CF\\u63D0\\u5347\\uFF09\\u662F\\u4E00\\u4E2A\\u672F\\u8BED\\uFF0C\\u7528\\u4E8E\\u89E3\\u91CA JavaScript \\u4EE3\\u7801\\u4E2D\\u53D8\\u91CF\\u58F0\\u660E\\u7684\\u884C\\u4E3A\\u3002\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u5173\\u952E\\u5B57\\u58F0\\u660E\\u6216\\u521D\\u59CB\\u5316\\u7684\\u53D8\\u91CF\\u5C06\\u5728\\u7F16\\u8BD1\\u671F\\u95F4\\u5C06\\u5176\\u58F0\\u660E\\u201C\\u79FB\\u52A8\\u201D\\u5230\\u5176\\u5305\\u542B\\u4F5C\\u7528\\u57DF\\u7684\\u9876\\u90E8\\uFF0C\\u6211\\u4EEC\\u5C06\\u5176\\u79F0\\u4E3A\\u53D8\\u91CF\\u63D0\\u5347\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u53EA\\u6709\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\uFF0C\\u521D\\u59CB\\u5316/\\u8D4B\\u503C\\uFF08\\u5982\\u679C\\u5B58\\u5728\\uFF09\\u5C06\\u4FDD\\u7559\\u5728\\u539F\\u6765\\u7684\\u4F4D\\u7F6E\\u3002\\u8BF7\\u6CE8\\u610F\\uFF0C\\u58F0\\u660E\\u5B9E\\u9645\\u4E0A\\u5E76\\u6CA1\\u6709\\u79FB\\u52A8\\u2014\\u2014JavaScript \\u5F15\\u64CE\\u5728\\u7F16\\u8BD1\\u671F\\u95F4\\u4F1A\\u89E3\\u6790\\u58F0\\u660E\\uFF0C\\u5E76\\u4E86\\u89E3\\u53D8\\u91CF\\u53CA\\u5176\\u4F5C\\u7528\\u57DF\\uFF0C\\u4F46\\u662F\\u901A\\u8FC7\\u5C06\\u58F0\\u660E\\u53EF\\u89C6\\u5316\\u4E3A\\u201C\\u63D0\\u5347\\u201D\\u5230\\u5176\\u4F5C\\u7528\\u57DF\\u7684\\u9876\\u90E8\\uFF0C\\u66F4\\u5BB9\\u6613\\u7406\\u89E3\\u8FD9\\u79CD\\u884C\\u4E3A\\u3002\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BA9\\u6211\\u4EEC\\u7528\\u51E0\\u4E2A\\u4EE3\\u7801\\u793A\\u4F8B\\u6765\\u89E3\\u91CA\\u3002\\u8BF7\\u6CE8\\u610F\\uFF0C\\u8FD9\\u4E9B\\u793A\\u4F8B\\u7684\\u4EE3\\u7801\\u5E94\\u8BE5\\u5728\\u6A21\\u5757\\u4F5C\\u7528\\u57DF\\u5185\\u6267\\u884C\\uFF0C\\u800C\\u4E0D\\u662F\\u50CF\\u6D4F\\u89C8\\u5668\\u63A7\\u5236\\u53F0\\u90A3\\u6837\\u9010\\u884C\\u8F93\\u5165\\u5230 REPL \\u4E2D\\u3002\"}),`\n`,(0,n.jsxs)(e.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u58F0\\u660E\\u7684\\u53D8\\u91CF\\u7684\\u53D8\\u91CF\\u63D0\\u5347\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u8FD9\\u91CC\\u53EF\\u4EE5\\u770B\\u5230\\u53D8\\u91CF\\u63D0\\u5347\\u7684\\u5B9E\\u9645\\u6548\\u679C\\uFF0C\\u5373\\u4F7F\\u5728\\u7B2C\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"console.log()\"}),\" \\u4E4B\\u540E\\u624D\\u58F0\\u660E\\u548C\\u521D\\u59CB\\u5316 \",(0,n.jsx)(e.code,{children:\"foo\"}),\"\\uFF0C\\u7B2C\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"console.log()\"}),\" \\u4E5F\\u4F1A\\u5C06 \",(0,n.jsx)(e.code,{children:\"foo\"}),\" \\u7684\\u503C\\u6253\\u5370\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(foo); // undefined\nvar foo = 1;\nconsole.log(foo); // 1\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"\\u60A8\\u53EF\\u4EE5\\u5C06\\u4EE3\\u7801\\u53EF\\u89C6\\u5316\\u4E3A\\uFF1A\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`var foo;\nconsole.log(foo); // undefined\nfoo = 1;\nconsole.log(foo); // 1\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"let\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"const\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"class\"}),\" \\u58F0\\u660E\\u7684\\u53D8\\u91CF\\u7684\\u53D8\\u91CF\\u63D0\\u5347\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u901A\\u8FC7 \",(0,n.jsx)(e.code,{children:\"let\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"const\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"class\"}),\" \\u58F0\\u660E\\u7684\\u53D8\\u91CF\\u4E5F\\u4F1A\\u88AB\\u63D0\\u5347\\u3002\\u4F46\\u662F\\uFF0C\\u4E0E \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"function\"}),\" \\u4E0D\\u540C\\uFF0C\\u5B83\\u4EEC\\u6CA1\\u6709\\u88AB\\u521D\\u59CB\\u5316\\uFF0C\\u5728\\u58F0\\u660E\\u4E4B\\u524D\\u8BBF\\u95EE\\u5B83\\u4EEC\\u5C06\\u5BFC\\u81F4 \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\" \\u5F02\\u5E38\\u3002\\u8BE5\\u53D8\\u91CF\\u5904\\u4E8E\\u4E00\\u4E2A\\u201C\\u6682\\u65F6\\u6027\\u6B7B\\u533A\\u201D\\uFF0C\\u4ECE\\u5757\\u7684\\u5F00\\u59CB\\u5230\\u58F0\\u660E\\u88AB\\u5904\\u7406\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`y; // ReferenceError: Cannot access 'y' before initialization\nlet y = 'local';\n`})}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`z; // ReferenceError: Cannot access 'z' before initialization\nconst z = 'local';\n`})}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`Foo; // ReferenceError: Cannot access 'Foo' before initialization\n\nclass Foo {\n constructor() {}\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u51FD\\u6570\\u8868\\u8FBE\\u5F0F\\u7684\\u63D0\\u5347\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u51FD\\u6570\\u8868\\u8FBE\\u5F0F\\u662F\\u4EE5\\u53D8\\u91CF\\u58F0\\u660E\\u7684\\u5F62\\u5F0F\\u7F16\\u5199\\u7684\\u51FD\\u6570\\u3002\\u7531\\u4E8E\\u5B83\\u4EEC\\u4E5F\\u662F\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u58F0\\u660E\\u7684\\uFF0C\\u56E0\\u6B64\\u53EA\\u6709\\u53D8\\u91CF\\u58F0\\u660E\\u88AB\\u63D0\\u5347\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(bar); // undefined\nbar(); // Uncaught TypeError: bar is not a function\n\nvar bar = function () {\n console.log('BARRRR');\n};\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u51FD\\u6570\\u58F0\\u660E\\u7684\\u63D0\\u5347\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u51FD\\u6570\\u58F0\\u660E\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"function\"}),\" \\u5173\\u952E\\u5B57\\u3002\\u4E0E\\u51FD\\u6570\\u8868\\u8FBE\\u5F0F\\u4E0D\\u540C\\uFF0C\\u51FD\\u6570\\u58F0\\u660E\\u540C\\u65F6\\u63D0\\u5347\\u58F0\\u660E\\u548C\\u5B9A\\u4E49\\uFF0C\\u56E0\\u6B64\\u5373\\u4F7F\\u5728\\u58F0\\u660E\\u4E4B\\u524D\\u4E5F\\u53EF\\u4EE5\\u8C03\\u7528\\u5B83\\u4EEC\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`console.log(foo); // [Function: foo]\nfoo(); // 'FOOOOO'\n\nfunction foo() {\n console.log('FOOOOO');\n}\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u540C\\u6837\\u9002\\u7528\\u4E8E\\u751F\\u6210\\u5668 (\",(0,n.jsx)(e.code,{children:\"function*\"}),\")\\u3001\\u5F02\\u6B65\\u51FD\\u6570 (\",(0,n.jsx)(e.code,{children:\"async function\"}),\") \\u548C\\u5F02\\u6B65\\u51FD\\u6570\\u751F\\u6210\\u5668 (\",(0,n.jsx)(e.code,{children:\"async function*\"}),\")\\u3002\"]}),`\n`,(0,n.jsxs)(e.h3,{children:[(0,n.jsx)(e.code,{children:\"import\"}),\" \\u8BED\\u53E5\\u7684\\u63D0\\u5347\"]}),`\n`,(0,n.jsx)(e.p,{children:\"Import \\u58F0\\u660E\\u88AB\\u63D0\\u5347\\u3002import \\u5F15\\u5165\\u7684\\u6807\\u8BC6\\u7B26\\u5728\\u6574\\u4E2A\\u6A21\\u5757\\u8303\\u56F4\\u5185\\u90FD\\u53EF\\u7528\\uFF0C\\u5E76\\u4E14\\u5B83\\u4EEC\\u4EA7\\u751F\\u7684\\u526F\\u4F5C\\u7528\\u5728\\u6A21\\u5757\\u7684\\u5176\\u4F59\\u4EE3\\u7801\\u8FD0\\u884C\\u4E4B\\u524D\\u4EA7\\u751F\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`foo.doSomething(); // Works normally.\n\nimport foo from './modules/foo';\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5E55\\u540E\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5B9E\\u9645\\u4E0A\\uFF0CJavaScript \\u5728\\u5C1D\\u8BD5\\u6267\\u884C\\u4EE3\\u7801\\u4E4B\\u524D\\uFF0C\\u4F1A\\u5728\\u5F53\\u524D\\u4F5C\\u7528\\u57DF\\u4E2D\\u521B\\u5EFA\\u6240\\u6709\\u53D8\\u91CF\\u3002\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u5173\\u952E\\u5B57\\u521B\\u5EFA\\u7684\\u53D8\\u91CF\\u7684\\u503C\\u5C06\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\uFF0C\\u800C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"let\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"const\"}),\" \\u5173\\u952E\\u5B57\\u521B\\u5EFA\\u7684\\u53D8\\u91CF\\u5C06\\u88AB\\u6807\\u8BB0\\u4E3A \",(0,n.jsx)(e.code,{children:\"\"}),\"\\u3002\\u56E0\\u6B64\\uFF0C\\u5728\\u521D\\u59CB\\u5316\\u4E4B\\u524D\\u8BBF\\u95EE\\u5B83\\u4EEC\\u5C06\\u5BFC\\u81F4 \",(0,n.jsx)(e.code,{children:\"ReferenceError\"}),\"\\uFF0C\\u4ECE\\u800C\\u963B\\u6B62\\u60A8\\u5728\\u521D\\u59CB\\u5316\\u4E4B\\u524D\\u8BBF\\u95EE\\u5B83\\u4EEC\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728 ECMAScript \\u89C4\\u8303\\u4E2D\\uFF0C\",(0,n.jsx)(e.code,{children:\"let\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"const\"}),\" \\u58F0\\u660E\",(0,n.jsx)(e.a,{href:\"https://tc39.es/ecma262/#sec-let-and-const-declarations\",children:\"\\u89E3\\u91CA\\u5982\\u4E0B\"}),\"\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsx)(e.p,{children:\"\\u5F53\\u5B83\\u4EEC\\u5305\\u542B\\u7684 Environment Record \\u88AB\\u5B9E\\u4F8B\\u5316\\u65F6\\uFF0C\\u53D8\\u91CF\\u88AB\\u521B\\u5EFA\\uFF0C\\u4F46\\u5728\\u53D8\\u91CF\\u7684 LexicalBinding \\u88AB\\u6C42\\u503C\\u4E4B\\u524D\\uFF0C\\u53EF\\u80FD\\u65E0\\u6CD5\\u4EE5\\u4EFB\\u4F55\\u65B9\\u5F0F\\u8BBF\\u95EE\\u5B83\\u4EEC\\u3002\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F46\\u662F\\uFF0C\\u5BF9\\u4E8E \",(0,n.jsx)(e.code,{children:\"var\"}),\" \\u5173\\u952E\\u5B57\\uFF0C\\u6B64\\u8BED\\u53E5\",(0,n.jsx)(e.a,{href:\"https://tc39.es/ecma262/#sec-variable-statement\",children:\"\\u7565\\u6709\\u4E0D\\u540C\"}),\"\\uFF1A\"]}),`\n`,(0,n.jsxs)(e.blockquote,{children:[`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5F53\\u5B83\\u4EEC\\u5305\\u542B\\u7684 Environment Record \\u88AB\\u5B9E\\u4F8B\\u5316\\u65F6\\uFF0CVar \\u53D8\\u91CF\\u88AB\\u521B\\u5EFA\\uFF0C\\u5E76\\u5728\\u521B\\u5EFA\\u65F6\\u88AB\\u521D\\u59CB\\u5316\\u4E3A \",(0,n.jsx)(e.code,{children:\"undefined\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u73B0\\u4EE3\\u5B9E\\u8DF5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5728\\u5B9E\\u8DF5\\u4E2D\\uFF0C\\u73B0\\u4EE3\\u4EE3\\u7801\\u5E93\\u907F\\u514D\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"var\"}),\"\\uFF0C\\u5E76\\u4E14\\u4EC5\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"let\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"const\"}),\"\\u3002\\u5EFA\\u8BAE\\u5728\\u5305\\u542B\\u8303\\u56F4/\\u6A21\\u5757\\u7684\\u9876\\u90E8\\u58F0\\u660E\\u548C\\u521D\\u59CB\\u5316\\u53D8\\u91CF\\u548C import \\u8BED\\u53E5\\uFF0C\\u4EE5\\u6D88\\u9664\\u8DDF\\u8E2A\\u4F55\\u65F6\\u53EF\\u4EE5\\u4F7F\\u7528\\u53D8\\u91CF\\u7684\\u5FC3\\u7406\\u8D1F\\u62C5\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"ESLint \\u662F\\u4E00\\u4E2A\\u9759\\u6001\\u4EE3\\u7801\\u5206\\u6790\\u5668\\uFF0C\\u53EF\\u4EE5\\u53D1\\u73B0\\u8FDD\\u53CD\\u6B64\\u7C7B\\u60C5\\u51B5\\uFF0C\\u4F7F\\u7528\\u4EE5\\u4E0B\\u89C4\\u5219\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"https://eslint.org/docs/latest/rules/no-use-before-define\",children:(0,n.jsx)(e.code,{children:\"no-use-before-define\"})}),\": \\u5F53\\u9047\\u5230\\u5BF9\\u5C1A\\u672A\\u58F0\\u660E\\u7684\\u6807\\u8BC6\\u7B26\\u7684\\u5F15\\u7528\\u65F6\\uFF0C\\u6B64\\u89C4\\u5219\\u5C06\\u53D1\\u51FA\\u8B66\\u544A\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.a,{href:\"https://eslint.org/docs/latest/rules/no-undef\",children:(0,n.jsx)(e.code,{children:\"no-undef\"})}),\": \\u5F53\\u9047\\u5230\\u5BF9\\u5C1A\\u672A\\u58F0\\u660E\\u7684\\u6807\\u8BC6\\u7B26\\u7684\\u5F15\\u7528\\u65F6\\uFF0C\\u6B64\\u89C4\\u5219\\u5C06\\u53D1\\u51FA\\u8B66\\u544A\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Glossary/Hoisting\",children:\"Hoisting | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://www.freecodecamp.org/news/what-is-hoisting-in-javascript\",children:\"What is Hoisting in JavaScript?\"})}),`\n`]})]})}function E(c={}){let{wrapper:e}=c.components||{};return e?(0,n.jsx)(e,Object.assign({},c,{children:(0,n.jsx)(a,c)})):a(c)}var y=E;return R(O);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-how-prototypal-inheritance-works/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-how-prototypal-inheritance-works/locales/en-US.json
index a3d787b19..86b6546d6 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-how-prototypal-inheritance-works/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-how-prototypal-inheritance-works/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain how prototypal inheritance works in JavaScript",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/explain-how-prototypal-inheritance-works/en-US.mdx"
},
- "solution": "var Component=(()=>{var d=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var f=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),b=(o,e)=>{for(var t in e)i(o,t,{get:e[t],enumerable:!0})},a=(o,e,t,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of y(e))!u.call(o,r)&&r!==t&&i(o,r,{get:()=>e[r],enumerable:!(c=p(e,r))||c.enumerable});return o};var j=(o,e,t)=>(t=o!=null?d(m(o)):{},a(e||!o||!o.__esModule?i(t,\"default\",{value:o,enumerable:!0}):t,o)),g=o=>a(i({},\"__esModule\",{value:!0}),o);var h=f((D,s)=>{s.exports=_jsx_runtime});var O={};b(O,{default:()=>v,frontmatter:()=>w});var n=j(h()),w={title:\"Explain how prototypal inheritance works in JavaScript\"};function l(o){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",a:\"a\",pre:\"pre\",ul:\"ul\",li:\"li\",hr:\"hr\",h3:\"h3\",ol:\"ol\",strong:\"strong\"},o.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Prototypical inheritance in JavaScript is a way for objects to inherit properties and methods from other objects. Every JavaScript object has a special hidden property called \",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\" (commonly accessed via \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" or using \",(0,n.jsx)(e.code,{children:\"Object.getPrototypeOf()\"}),`) that is a reference to another object, which is called the object's \"prototype\".`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"When a property is accessed on an object and if the property is not found on that object, the JavaScript engine looks at the object's \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\", and the \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\"'s \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" and so on, until it finds the property defined on one of the \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\"s or until it reaches the end of the prototype chain.\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"This behavior simulates classical inheritance, but it is really more of \",(0,n.jsx)(e.a,{href:\"https://davidwalsh.name/javascript-objects\",children:\"delegation than inheritance\"}),\".\"]}),`\n`,(0,n.jsx)(e.p,{children:\"Here's an example of prototypal inheritance:\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Parent object constructor.\nfunction Animal(name) {\n this.name = name;\n}\n\n// Add a method to the parent object's prototype.\nAnimal.prototype.makeSound = function () {\n console.log('The ' + this.constructor.name + ' makes a sound.');\n};\n\n// Child object constructor.\nfunction Dog(name) {\n Animal.call(this, name); // Call the parent constructor.\n}\n\n// Set the child object's prototype to be the parent's prototype.\nObject.setPrototypeOf(Dog.prototype, Animal.prototype);\n\n// Add a method to the child object's prototype.\nDog.prototype.bark = function () {\n console.log('Woof!');\n};\n\n// Create a new instance of Dog.\nconst bolt = new Dog('Bolt');\n\n// Call methods on the child object.\nconsole.log(bolt.name); // \"Bolt\"\nbolt.makeSound(); // \"The Dog makes a sound.\"\nbolt.bark(); // \"Woof!\"\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"Things to note are:\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\".makeSound\"}),\" is not defined on \",(0,n.jsx)(e.code,{children:\"Dog\"}),\", so the JavaScript engine goes up the prototype chain and finds \",(0,n.jsx)(e.code,{children:\".makeSound\"}),\" on the inherited \",(0,n.jsx)(e.code,{children:\"Animal\"}),\".\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"Object.create()\"}),\" to build the inheritance chain is no longer recommended. Use \",(0,n.jsx)(e.code,{children:\"Object.setPrototypeOf()\"}),\" instead.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Prototypical Inheritance in Javascript\"}),`\n`,(0,n.jsx)(e.p,{children:\"Prototypical inheritance is a feature in JavaScript used to create objects that inherit properties and methods from other objects. Instead of a class-based inheritance model, JavaScript uses a prototype-based model, where objects can directly inherit from other objects.\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Key Concepts\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Prototypes\"}),\" : Every object in Javascript has a prototype, which is another object. When you create an object using an object literal or a constructor function, the new object is linked to the prototype of its constructor function or the \",(0,n.jsx)(e.code,{children:\"Object.prototype\"}),\" if no prototype is specified. This is commonly referenced using \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" or \",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\". You can also get the prototype by using inbuilt method \",(0,n.jsx)(e.code,{children:\"Object.getPrototypeOf()\"}),\" and you can set the prototype of an object via \",(0,n.jsx)(e.code,{children:\"Object.setPrototypeOf()\"}),\".\"]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Define a constructor function\nfunction Person(name, age) {\n this.name = name;\n this.age = age;\n}\n\n// Add a method to the prototype\nPerson.prototype.sayHello = function () {\n console.log(\\`Hello, my name is \\${this.name} and I am \\${this.age} years old.\\`);\n};\n\n// Create a new object using the constructor function\nlet john = new Person('John', 30);\n\n// The new object has access to the methods defined on the prototype\njohn.sayHello(); // \"Hello, my name is John and I am 30 years old.\"\n\n// The prototype of the new object is the prototype of the constructor function\nconsole.log(john.__proto__ === Person.prototype); // true\n\n// You can also get the prototype using Object.getPrototypeOf()\nconsole.log(Object.getPrototypeOf(john) === Person.prototype); // true\n\n// You can set the prototype of an object using Object.setPrototypeOf()\nlet newProto = {\n sayGoodbye: function () {\n console.log(\\`Goodbye, my name is \\${this.name}\\`);\n },\n};\n\nObject.setPrototypeOf(john, newProto);\n\n// Now john has access to the methods defined on the new prototype\njohn.sayGoodbye(); // \"Goodbye, my name is John\"\n\n// But no longer has access to the methods defined on the old prototype\nconsole.log(john.sayHello); // undefined\n`})}),`\n`,(0,n.jsxs)(e.ol,{start:\"2\",children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"Prototype chain\"}),\": When a property or method is accessed on an object, JavaScript first looks for it on the object itself. If it doesn't find it there, it looks at the object's prototype, and then the prototype's prototype, and so on, until it either finds the property or reaches the end of the chain (i.e., \",(0,n.jsx)(e.code,{children:\"null\"}),\").\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"Constructor functions\"}),\": JavaScript provides constructor functions to create objects. When a function is used as a constructor with the new keyword, the new object's prototype (\",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\") is set to the constructor's prototype property.\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Define a constructor function\nfunction Animal(name) {\n this.name = name;\n}\n\n// Add a method to the prototype\nAnimal.prototype.sayName = function () {\n console.log(\\`My name is \\${this.name}\\`);\n};\n\n// Define a new constructor function\nfunction Dog(name, breed) {\n Animal.call(this, name);\n this.breed = breed;\n}\n\n// Set the prototype of Dog to be a new instance of Animal\nDog.prototype = Object.create(Animal.prototype);\n\n// Add a method to the Dog prototype\nDog.prototype.bark = function () {\n console.log('Woof!');\n};\n\n// Create a new object using the Dog constructor function\nlet fido = new Dog('Fido', 'Labrador');\n\n// The new object has access to the methods defined on its own prototype and the Animal prototype\nfido.bark(); // \"Woof!\"\nfido.sayName(); // \"My name is Fido\"\n\n// If we try to access a method that doesn't exist on the Dog prototype or the Animal prototype, JavaScript will return undefined\nconsole.log(fido.fly); // undefined\n`})}),`\n`,(0,n.jsxs)(e.ol,{start:\"4\",children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:(0,n.jsx)(e.code,{children:\"Object.create()\"})}),\": This method creates a new object with the specified prototype object and properties. It's a straightforward way to set up prototypical inheritance. If you create a object via \",(0,n.jsx)(e.code,{children:\"Object.create(null)\"}),\" it will not inherit any properties from \",(0,n.jsx)(e.code,{children:\"Object.prototype\"}),\". This means the object will not have any built-in properties or methods like \",(0,n.jsx)(e.code,{children:\"toString()\"}),\", \",(0,n.jsx)(e.code,{children:\"hasOwnProperty()\"}),\",\"]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Define a prototype object\nlet proto = {\n greet: function () {\n console.log(\\`Hello, my name is \\${this.name}\\`);\n },\n};\n\n// Use \\`Object.create()\\` to create a new object with the specified prototype\nlet person = Object.create(proto);\nperson.name = 'John';\n\n// The new object has access to the methods defined on the prototype\nperson.greet(); // \"Hello, my name is John\"\n\n// Check if the object has a property\nconsole.log(person.hasOwnProperty('name')); // true\n\n// Create an object that does not inherit from Object.prototype\nlet animal = Object.create(null);\nanimal.name = 'Rocky';\n\n// The new object does not have any built-in properties or methods\nconsole.log(animal.toString); // undefined\nconsole.log(animal.hasOwnProperty); // undefined\n\n// But you can still add and access custom properties\nanimal.describe = function () {\n console.log(\\`Name of the animal is \\${this.name}\\`);\n};\n\nanimal.describe(); // \"Name of the animal is Rocky\"\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Resources\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain\",children:\"Inheritance and the prototype chain | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://dev.to/lydiahallie/javascript-visualized-prototypal-inheritance-47co\",children:\"JavaScript Visualized: Prototypal Inheritance\"})}),`\n`]})]})}function _(o={}){let{wrapper:e}=o.components||{};return e?(0,n.jsx)(e,Object.assign({},o,{children:(0,n.jsx)(l,o)})):l(o)}var v=_;return g(O);})();\n;return Component;"
+ "solution": "var Component=(()=>{var d=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var n in e)i(t,n,{get:e[n],enumerable:!0})},a=(t,e,n,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of y(e))!u.call(t,r)&&r!==n&&i(t,r,{get:()=>e[r],enumerable:!(c=p(e,r))||c.enumerable});return t};var j=(t,e,n)=>(n=t!=null?d(m(t)):{},a(e||!t||!t.__esModule?i(n,\"default\",{value:t,enumerable:!0}):n,t)),g=t=>a(i({},\"__esModule\",{value:!0}),t);var h=f((D,s)=>{s.exports=_jsx_runtime});var O={};b(O,{default:()=>v,frontmatter:()=>w});var o=j(h()),w={title:\"Explain how prototypal inheritance works in JavaScript\"};function l(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",a:\"a\",pre:\"pre\",ul:\"ul\",li:\"li\",hr:\"hr\",h3:\"h3\",ol:\"ol\",strong:\"strong\"},t.components);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,o.jsxs)(e.p,{children:[\"Prototypical inheritance in JavaScript is a way for objects to inherit properties and methods from other objects. Every JavaScript object has a special hidden property called \",(0,o.jsx)(e.code,{children:\"[[Prototype]]\"}),\" (commonly accessed via \",(0,o.jsx)(e.code,{children:\"__proto__\"}),\" or using \",(0,o.jsx)(e.code,{children:\"Object.getPrototypeOf()\"}),`) that is a reference to another object, which is called the object's \"prototype\".`]}),`\n`,(0,o.jsxs)(e.p,{children:[\"When a property is accessed on an object and if the property is not found on that object, the JavaScript engine looks at the object's \",(0,o.jsx)(e.code,{children:\"__proto__\"}),\", and the \",(0,o.jsx)(e.code,{children:\"__proto__\"}),\"'s \",(0,o.jsx)(e.code,{children:\"__proto__\"}),\" and so on, until it finds the property defined on one of the \",(0,o.jsx)(e.code,{children:\"__proto__\"}),\"s or until it reaches the end of the prototype chain.\"]}),`\n`,(0,o.jsxs)(e.p,{children:[\"This behavior simulates classical inheritance, but it is really more of \",(0,o.jsx)(e.a,{href:\"https://davidwalsh.name/javascript-objects\",children:\"delegation than inheritance\"}),\".\"]}),`\n`,(0,o.jsx)(e.p,{children:\"Here's an example of prototypal inheritance:\"}),`\n`,(0,o.jsx)(e.pre,{live:!0,children:(0,o.jsx)(e.code,{className:\"language-js\",children:`// Parent object constructor.\nfunction Animal(name) {\n this.name = name;\n}\n\n// Add a method to the parent object's prototype.\nAnimal.prototype.makeSound = function () {\n console.log('The ' + this.constructor.name + ' makes a sound.');\n};\n\n// Child object constructor.\nfunction Dog(name) {\n Animal.call(this, name); // Call the parent constructor.\n}\n\n// Set the child object's prototype to be the parent's prototype.\nObject.setPrototypeOf(Dog.prototype, Animal.prototype);\n\n// Add a method to the child object's prototype.\nDog.prototype.bark = function () {\n console.log('Woof!');\n};\n\n// Create a new instance of Dog.\nconst bolt = new Dog('Bolt');\n\n// Call methods on the child object.\nconsole.log(bolt.name); // \"Bolt\"\nbolt.makeSound(); // \"The Dog makes a sound.\"\nbolt.bark(); // \"Woof!\"\n`})}),`\n`,(0,o.jsx)(e.p,{children:\"Things to note are:\"}),`\n`,(0,o.jsxs)(e.ul,{children:[`\n`,(0,o.jsxs)(e.li,{children:[(0,o.jsx)(e.code,{children:\".makeSound\"}),\" is not defined on \",(0,o.jsx)(e.code,{children:\"Dog\"}),\", so the JavaScript engine goes up the prototype chain and finds \",(0,o.jsx)(e.code,{children:\".makeSound\"}),\" on the inherited \",(0,o.jsx)(e.code,{children:\"Animal\"}),\".\"]}),`\n`,(0,o.jsxs)(e.li,{children:[\"Using \",(0,o.jsx)(e.code,{children:\"Object.create()\"}),\" to build the inheritance chain is no longer recommended. Use \",(0,o.jsx)(e.code,{children:\"Object.setPrototypeOf()\"}),\" instead.\"]}),`\n`]}),`\n`,(0,o.jsx)(e.hr,{}),`\n`,(0,o.jsx)(e.h2,{children:\"Prototypical Inheritance in Javascript\"}),`\n`,(0,o.jsx)(e.p,{children:\"Prototypical inheritance is a feature in JavaScript used to create objects that inherit properties and methods from other objects. Instead of a class-based inheritance model, JavaScript uses a prototype-based model, where objects can directly inherit from other objects.\"}),`\n`,(0,o.jsx)(e.h3,{children:\"Key Concepts\"}),`\n`,(0,o.jsxs)(e.ol,{children:[`\n`,(0,o.jsxs)(e.li,{children:[(0,o.jsx)(e.strong,{children:\"Prototypes\"}),\" : Every object in Javascript has a prototype, which is another object. When you create an object using an object literal or a constructor function, the new object is linked to the prototype of its constructor function or the \",(0,o.jsx)(e.code,{children:\"Object.prototype\"}),\" if no prototype is specified. This is commonly referenced using \",(0,o.jsx)(e.code,{children:\"__proto__\"}),\" or \",(0,o.jsx)(e.code,{children:\"[[Prototype]]\"}),\". You can also get the prototype by using inbuilt method \",(0,o.jsx)(e.code,{children:\"Object.getPrototypeOf()\"}),\" and you can set the prototype of an object via \",(0,o.jsx)(e.code,{children:\"Object.setPrototypeOf()\"}),\".\"]}),`\n`]}),`\n`,(0,o.jsx)(e.pre,{live:!0,children:(0,o.jsx)(e.code,{className:\"language-js\",children:`// Define a constructor function\nfunction Person(name, age) {\n this.name = name;\n this.age = age;\n}\n\n// Add a method to the prototype\nPerson.prototype.sayHello = function () {\n console.log(\\`Hello, my name is \\${this.name} and I am \\${this.age} years old.\\`);\n};\n\n// Create a new object using the constructor function\nlet john = new Person('John', 30);\n\n// The new object has access to the methods defined on the prototype\njohn.sayHello(); // \"Hello, my name is John and I am 30 years old.\"\n\n// The prototype of the new object is the prototype of the constructor function\nconsole.log(john.__proto__ === Person.prototype); // true\n\n// You can also get the prototype using Object.getPrototypeOf()\nconsole.log(Object.getPrototypeOf(john) === Person.prototype); // true\n\n// You can set the prototype of an object using Object.setPrototypeOf()\nlet newProto = {\n sayGoodbye: function () {\n console.log(\\`Goodbye, my name is \\${this.name}\\`);\n },\n};\n\nObject.setPrototypeOf(john, newProto);\n\n// Now john has access to the methods defined on the new prototype\njohn.sayGoodbye(); // \"Goodbye, my name is John\"\n\n// But no longer has access to the methods defined on the old prototype\nconsole.log(john.sayHello); // undefined\n`})}),`\n`,(0,o.jsxs)(e.ol,{start:\"2\",children:[`\n`,(0,o.jsxs)(e.li,{children:[`\n`,(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.strong,{children:\"Prototype chain\"}),\": When a property or method is accessed on an object, JavaScript first looks for it on the object itself. If it doesn't find it there, it looks at the object's prototype, and then the prototype's prototype, and so on, until it either finds the property or reaches the end of the chain (i.e., \",(0,o.jsx)(e.code,{children:\"null\"}),\").\"]}),`\n`]}),`\n`,(0,o.jsxs)(e.li,{children:[`\n`,(0,o.jsxs)(e.p,{children:[(0,o.jsx)(e.strong,{children:\"Constructor functions\"}),\": JavaScript provides constructor functions to create objects. When a function is used as a constructor with the new keyword, the new object's prototype (\",(0,o.jsx)(e.code,{children:\"[[Prototype]]\"}),\") is set to the constructor's prototype property.\"]}),`\n`]}),`\n`]}),`\n`,(0,o.jsx)(e.pre,{live:!0,children:(0,o.jsx)(e.code,{className:\"language-js\",children:`// Define a constructor function\nfunction Animal(name) {\n this.name = name;\n}\n\n// Add a method to the prototype\nAnimal.prototype.sayName = function () {\n console.log(\\`My name is \\${this.name}\\`);\n};\n\n// Define a new constructor function\nfunction Dog(name, breed) {\n Animal.call(this, name);\n this.breed = breed;\n}\n\n// Set the prototype of Dog to inherit from Animal's prototype\nObject.setPrototypeOf(Dog.prototype, Animal.prototype);\n\n// Add a method to the Dog prototype\nDog.prototype.bark = function () {\n console.log('Woof!');\n};\n\n// Create a new object using the Dog constructor function\nlet fido = new Dog('Fido', 'Labrador');\n\n// The new object has access to the methods defined on its own prototype and the Animal prototype\nfido.bark(); // \"Woof!\"\nfido.sayName(); // \"My name is Fido\"\n\n// If we try to access a method that doesn't exist on the Dog prototype or the Animal prototype, JavaScript will return undefined\nconsole.log(fido.fly); // undefined\n`})}),`\n`,(0,o.jsxs)(e.ol,{start:\"4\",children:[`\n`,(0,o.jsxs)(e.li,{children:[(0,o.jsx)(e.strong,{children:(0,o.jsx)(e.code,{children:\"Object.create()\"})}),\": This method creates a new object whose internal \",(0,o.jsx)(e.code,{children:\"[[Prototype]]\"}),\" is directly linked to the specified prototype object. It's the most direct way to create an object that inherits from another specific object, without involving constructor functions. If you create a object via \",(0,o.jsx)(e.code,{children:\"Object.create(null)\"}),\" it will not inherit any properties from \",(0,o.jsx)(e.code,{children:\"Object.prototype\"}),\". This means the object will not have any built-in properties or methods like \",(0,o.jsx)(e.code,{children:\"toString()\"}),\", \",(0,o.jsx)(e.code,{children:\"hasOwnProperty()\"}),\",\"]}),`\n`]}),`\n`,(0,o.jsx)(e.pre,{live:!0,children:(0,o.jsx)(e.code,{className:\"language-js\",children:`// Define a prototype object\nlet proto = {\n greet: function () {\n console.log(\\`Hello, my name is \\${this.name}\\`);\n },\n};\n\n// Use \\`Object.create()\\` to create a new object with the specified prototype\nlet person = Object.create(proto);\nperson.name = 'John';\n\n// The new object has access to the methods defined on the prototype\nperson.greet(); // \"Hello, my name is John\"\n\n// Check if the object has a property\nconsole.log(person.hasOwnProperty('name')); // true\n\n// Create an object that does not inherit from Object.prototype\nlet animal = Object.create(null);\nanimal.name = 'Rocky';\n\n// The new object does not have any built-in properties or methods\nconsole.log(animal.toString); // undefined\nconsole.log(animal.hasOwnProperty); // undefined\n\n// But you can still add and access custom properties\nanimal.describe = function () {\n console.log(\\`Name of the animal is \\${this.name}\\`);\n};\n\nanimal.describe(); // \"Name of the animal is Rocky\"\n`})}),`\n`,(0,o.jsx)(e.h2,{children:\"Resources\"}),`\n`,(0,o.jsxs)(e.ul,{children:[`\n`,(0,o.jsx)(e.li,{children:(0,o.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain\",children:\"Inheritance and the prototype chain | MDN\"})}),`\n`,(0,o.jsx)(e.li,{children:(0,o.jsx)(e.a,{href:\"https://dev.to/lydiahallie/javascript-visualized-prototypal-inheritance-47co\",children:\"JavaScript Visualized: Prototypal Inheritance\"})}),`\n`]})]})}function _(t={}){let{wrapper:e}=t.components||{};return e?(0,o.jsx)(e,Object.assign({},t,{children:(0,o.jsx)(l,t)})):l(t)}var v=_;return g(O);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-how-prototypal-inheritance-works/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-how-prototypal-inheritance-works/locales/zh-CN.json
index 2fdb6fea4..ce07db55c 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-how-prototypal-inheritance-works/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-how-prototypal-inheritance-works/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释 JavaScript 中原型继承的工作原理",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/explain-how-prototypal-inheritance-works/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var f=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),g=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},i=(o,e,t,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!u.call(o,r)&&r!==t&&c(o,r,{get:()=>e[r],enumerable:!(a=p(e,r))||a.enumerable});return o};var b=(o,e,t)=>(t=o!=null?s(y(o)):{},i(e||!o||!o.__esModule?c(t,\"default\",{value:o,enumerable:!0}):t,o)),j=o=>i(c({},\"__esModule\",{value:!0}),o);var h=f((D,l)=>{l.exports=_jsx_runtime});var v={};g(v,{default:()=>w,frontmatter:()=>_});var n=b(h()),_={title:\"\\u89E3\\u91CA JavaScript \\u4E2D\\u539F\\u578B\\u7EE7\\u627F\\u7684\\u5DE5\\u4F5C\\u539F\\u7406\"};function d(o){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",a:\"a\",pre:\"pre\",ul:\"ul\",li:\"li\",hr:\"hr\",h3:\"h3\",ol:\"ol\",strong:\"strong\"},o.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"JavaScript \\u4E2D\\u7684\\u539F\\u578B\\u7EE7\\u627F\\u662F\\u5BF9\\u8C61\\u4ECE\\u5176\\u4ED6\\u5BF9\\u8C61\\u7EE7\\u627F\\u5C5E\\u6027\\u548C\\u65B9\\u6CD5\\u7684\\u4E00\\u79CD\\u65B9\\u5F0F\\u3002\\u6BCF\\u4E2A JavaScript \\u5BF9\\u8C61\\u90FD\\u6709\\u4E00\\u4E2A\\u540D\\u4E3A \",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\" \\u7684\\u7279\\u6B8A\\u9690\\u85CF\\u5C5E\\u6027\\uFF08\\u901A\\u5E38\\u901A\\u8FC7 \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" \\u6216\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Object.getPrototypeOf()\"}),\" \\u8BBF\\u95EE\\uFF09\\uFF0C\\u5B83\\u5F15\\u7528\\u53E6\\u4E00\\u4E2A\\u5BF9\\u8C61\\uFF0C\\u8BE5\\u5BF9\\u8C61\\u88AB\\u79F0\\u4E3A\\u5BF9\\u8C61\\u7684\\u201C\\u539F\\u578B\\u201D\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5F53\\u8BBF\\u95EE\\u5BF9\\u8C61\\u7684\\u5C5E\\u6027\\uFF0C\\u5E76\\u4E14\\u5728\\u8BE5\\u5BF9\\u8C61\\u4E0A\\u627E\\u4E0D\\u5230\\u8BE5\\u5C5E\\u6027\\u65F6\\uFF0CJavaScript \\u5F15\\u64CE\\u4F1A\\u67E5\\u770B\\u5BF9\\u8C61\\u7684 \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\"\\uFF0C\\u4EE5\\u53CA \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\"\\uFF0C\\u4F9D\\u6B64\\u7C7B\\u63A8\\uFF0C\\u76F4\\u5230\\u5B83\\u5728\\u5176\\u4E2D\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" \\u4E0A\\u627E\\u5230\\u5B9A\\u4E49\\u7684\\u5C5E\\u6027\\uFF0C\\u6216\\u8005\\u76F4\\u5230\\u5B83\\u5230\\u8FBE\\u539F\\u578B\\u94FE\\u7684\\u672B\\u5C3E\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u884C\\u4E3A\\u6A21\\u62DF\\u4E86\\u7ECF\\u5178\\u7EE7\\u627F\\uFF0C\\u4F46\\u5B9E\\u9645\\u4E0A\\u5B83\\u66F4\\u50CF\\u662F\",(0,n.jsx)(e.a,{href:\"https://davidwalsh.name/javascript-objects\",children:\"\\u59D4\\u6258\\u800C\\u4E0D\\u662F\\u7EE7\\u627F\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4EE5\\u4E0B\\u662F\\u539F\\u578B\\u7EE7\\u627F\\u7684\\u793A\\u4F8B\\uFF1A\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Parent object constructor.\nfunction Animal(name) {\n this.name = name;\n}\n\n// Add a method to the parent object's prototype.\nAnimal.prototype.makeSound = function () {\n console.log('The ' + this.constructor.name + ' makes a sound.');\n};\n\n// Child object constructor.\nfunction Dog(name) {\n Animal.call(this, name); // Call the parent constructor.\n}\n\n// Set the child object's prototype to be the parent's prototype.\nObject.setPrototypeOf(Dog.prototype, Animal.prototype);\n\n// Add a method to the child object's prototype.\nDog.prototype.bark = function () {\n console.log('Woof!');\n};\n\n// Create a new instance of Dog.\nconst bolt = new Dog('Bolt');\n\n// Call methods on the child object.\nconsole.log(bolt.name); // \"Bolt\"\nbolt.makeSound(); // \"The Dog makes a sound.\"\nbolt.bark(); // \"Woof!\"\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"\\u9700\\u8981\\u6CE8\\u610F\\u7684\\u662F\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\".makeSound\"}),\" \\u672A\\u5728 \",(0,n.jsx)(e.code,{children:\"Dog\"}),\" \\u4E0A\\u5B9A\\u4E49\\uFF0C\\u56E0\\u6B64 JavaScript \\u5F15\\u64CE\\u4F1A\\u5411\\u4E0A\\u67E5\\u627E\\u539F\\u578B\\u94FE\\uFF0C\\u5E76\\u5728\\u7EE7\\u627F\\u7684 \",(0,n.jsx)(e.code,{children:\"Animal\"}),\" \\u4E0A\\u627E\\u5230 \",(0,n.jsx)(e.code,{children:\".makeSound\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E0D\\u518D\\u63A8\\u8350\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Object.create()\"}),\" \\u6765\\u6784\\u5EFA\\u7EE7\\u627F\\u94FE\\u3002\\u8BF7\\u6539\\u7528 \",(0,n.jsx)(e.code,{children:\"Object.setPrototypeOf()\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Javascript \\u4E2D\\u7684\\u539F\\u578B\\u7EE7\\u627F\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u539F\\u578B\\u7EE7\\u627F\\u662F JavaScript \\u4E2D\\u7528\\u4E8E\\u521B\\u5EFA\\u4ECE\\u5176\\u4ED6\\u5BF9\\u8C61\\u7EE7\\u627F\\u5C5E\\u6027\\u548C\\u65B9\\u6CD5\\u5BF9\\u8C61\\u7684\\u7279\\u6027\\u3002JavaScript \\u4F7F\\u7528\\u57FA\\u4E8E\\u539F\\u578B\\u7684\\u6A21\\u578B\\uFF0C\\u800C\\u4E0D\\u662F\\u57FA\\u4E8E\\u7C7B\\u7684\\u7EE7\\u627F\\u6A21\\u578B\\uFF0C\\u5BF9\\u8C61\\u53EF\\u4EE5\\u76F4\\u63A5\\u4ECE\\u5176\\u4ED6\\u5BF9\\u8C61\\u7EE7\\u627F\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5173\\u952E\\u6982\\u5FF5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u539F\\u578B\"}),\"\\uFF1AJavaScript \\u4E2D\\u7684\\u6BCF\\u4E2A\\u5BF9\\u8C61\\u90FD\\u6709\\u4E00\\u4E2A\\u539F\\u578B\\uFF0C\\u5B83\\u4E5F\\u662F\\u4E00\\u4E2A\\u5BF9\\u8C61\\u3002\\u5F53\\u60A8\\u4F7F\\u7528\\u5BF9\\u8C61\\u5B57\\u9762\\u91CF\\u6216\\u6784\\u9020\\u51FD\\u6570\\u521B\\u5EFA\\u5BF9\\u8C61\\u65F6\\uFF0C\\u65B0\\u5BF9\\u8C61\\u5C06\\u94FE\\u63A5\\u5230\\u5176\\u6784\\u9020\\u51FD\\u6570\\u7684\\u539F\\u578B\\uFF0C\\u5982\\u679C\\u672A\\u6307\\u5B9A\\u539F\\u578B\\uFF0C\\u5219\\u94FE\\u63A5\\u5230 \",(0,n.jsx)(e.code,{children:\"Object.prototype\"}),\"\\u3002\\u8FD9\\u901A\\u5E38\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" \\u6216 \",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\" \\u5F15\\u7528\\u3002\\u60A8\\u8FD8\\u53EF\\u4EE5\\u4F7F\\u7528\\u5185\\u7F6E\\u65B9\\u6CD5 \",(0,n.jsx)(e.code,{children:\"Object.getPrototypeOf()\"}),\" \\u83B7\\u53D6\\u539F\\u578B\\uFF0C\\u5E76\\u4E14\\u53EF\\u4EE5\\u901A\\u8FC7 \",(0,n.jsx)(e.code,{children:\"Object.setPrototypeOf()\"}),\" \\u8BBE\\u7F6E\\u5BF9\\u8C61\\u7684\\u539F\\u578B\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Define a constructor function\nfunction Person(name, age) {\n this.name = name;\n this.age = age;\n}\n\n// Add a method to the prototype\nPerson.prototype.sayHello = function () {\n console.log(\\`Hello, my name is \\${this.name} and I am \\${this.age} years old.\\`);\n};\n\n// Create a new object using the constructor function\nlet john = new Person('John', 30);\n\n// The new object has access to the methods defined on the prototype\njohn.sayHello(); // \"Hello, my name is John and I am 30 years old.\"\n\n// The prototype of the new object is the prototype of the constructor function\nconsole.log(john.__proto__ === Person.prototype); // true\n\n// You can also get the prototype using Object.getPrototypeOf()\nconsole.log(Object.getPrototypeOf(john) === Person.prototype); // true\n\n// You can set the prototype of an object using Object.setPrototypeOf()\nlet newProto = {\n sayGoodbye: function () {\n console.log(\\`Goodbye, my name is \\${this.name}\\`);\n },\n};\n\nObject.setPrototypeOf(john, newProto);\n\n// Now john has access to the methods defined on the new prototype\njohn.sayGoodbye(); // \"Goodbye, my name is John\"\n\n// But no longer has access to the methods defined on the old prototype\nconsole.log(john.sayHello); // undefined\n`})}),`\n`,(0,n.jsxs)(e.ol,{start:\"2\",children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u539F\\u578B\\u94FE\"}),\"\\uFF1A\\u5F53\\u8BBF\\u95EE\\u5BF9\\u8C61\\u7684\\u5C5E\\u6027\\u6216\\u65B9\\u6CD5\\u65F6\\uFF0CJavaScript \\u9996\\u5148\\u5728\\u5BF9\\u8C61\\u672C\\u8EAB\\u4E0A\\u67E5\\u627E\\u5B83\\u3002\\u5982\\u679C\\u627E\\u4E0D\\u5230\\uFF0C\\u5B83\\u4F1A\\u67E5\\u770B\\u5BF9\\u8C61\\u7684\\u539F\\u578B\\uFF0C\\u7136\\u540E\\u662F\\u539F\\u578B\\u7684\\u539F\\u578B\\uFF0C\\u4F9D\\u6B64\\u7C7B\\u63A8\\uFF0C\\u76F4\\u5230\\u627E\\u5230\\u8BE5\\u5C5E\\u6027\\u6216\\u5230\\u8FBE\\u94FE\\u7684\\u672B\\u5C3E\\uFF08\\u5373 \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF09\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u6784\\u9020\\u51FD\\u6570\"}),\"\\uFF1AJavaScript \\u63D0\\u4F9B\\u4E86\\u6784\\u9020\\u51FD\\u6570\\u6765\\u521B\\u5EFA\\u5BF9\\u8C61\\u3002\\u5F53\\u4E00\\u4E2A\\u51FD\\u6570\\u4E0E new \\u5173\\u952E\\u5B57\\u4E00\\u8D77\\u7528\\u4F5C\\u6784\\u9020\\u51FD\\u6570\\u65F6\\uFF0C\\u65B0\\u5BF9\\u8C61\\u7684\\u539F\\u578B (\",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\") \\u5C06\\u8BBE\\u7F6E\\u4E3A\\u6784\\u9020\\u51FD\\u6570 \\u7684\\u539F\\u578B\\u5C5E\\u6027\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Define a constructor function\nfunction Animal(name) {\n this.name = name;\n}\n\n// Add a method to the prototype\nAnimal.prototype.sayName = function () {\n console.log(\\`My name is \\${this.name}\\`);\n};\n\n// Define a new constructor function\nfunction Dog(name, breed) {\n Animal.call(this, name);\n this.breed = breed;\n}\n\n// Set the prototype of Dog to be a new instance of Animal\nDog.prototype = Object.create(Animal.prototype);\n\n// Add a method to the Dog prototype\nDog.prototype.bark = function () {\n console.log('Woof!');\n};\n\n// Create a new object using the Dog constructor function\nlet fido = new Dog('Fido', 'Labrador');\n\n// The new object has access to the methods defined on its own prototype and the Animal prototype\nfido.bark(); // \"Woof!\"\nfido.sayName(); // \"My name is Fido\"\n\n// If we try to access a method that doesn't exist on the Dog prototype or the Animal prototype, JavaScript will return undefined\nconsole.log(fido.fly); // undefined\n`})}),`\n`,(0,n.jsxs)(e.ol,{start:\"4\",children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:(0,n.jsx)(e.code,{children:\"Object.create()\"})}),\"\\uFF1A\\u6B64\\u65B9\\u6CD5\\u4F7F\\u7528\\u6307\\u5B9A\\u539F\\u578B\\u5BF9\\u8C61\\u548C\\u5C5E\\u6027\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u5BF9\\u8C61\\u3002\\u8FD9\\u662F\\u8BBE\\u7F6E\\u539F\\u578B\\u7EE7\\u627F\\u7684\\u4E00\\u79CD\\u76F4\\u63A5\\u65B9\\u6CD5\\u3002\\u5982\\u679C\\u60A8\\u901A\\u8FC7 \",(0,n.jsx)(e.code,{children:\"Object.create(null)\"}),\" \\u521B\\u5EFA\\u4E00\\u4E2A\\u5BF9\\u8C61\\uFF0C\\u5B83\\u5C06\\u4E0D\\u4F1A\\u4ECE \",(0,n.jsx)(e.code,{children:\"Object.prototype\"}),\" \\u7EE7\\u627F\\u4EFB\\u4F55\\u5C5E\\u6027\\u3002\\u8FD9\\u610F\\u5473\\u7740\\u8BE5\\u5BF9\\u8C61\\u5C06\\u6CA1\\u6709\\u4EFB\\u4F55\\u5185\\u7F6E\\u5C5E\\u6027\\u6216\\u65B9\\u6CD5\\uFF0C\\u4F8B\\u5982 \",(0,n.jsx)(e.code,{children:\"toString()\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"hasOwnProperty()\"})]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Define a prototype object\nlet proto = {\n greet: function () {\n console.log(\\`Hello, my name is \\${this.name}\\`);\n },\n};\n\n// Use \\`Object.create()\\` to create a new object with the specified prototype\nlet person = Object.create(proto);\nperson.name = 'John';\n\n// The new object has access to the methods defined on the prototype\nperson.greet(); // \"Hello, my name is John\"\n\n// Check if the object has a property\nconsole.log(person.hasOwnProperty('name')); // true\n\n// Create an object that does not inherit from Object.prototype\nlet animal = Object.create(null);\nanimal.name = 'Rocky';\n\n// The new object does not have any built-in properties or methods\nconsole.log(animal.toString); // undefined\nconsole.log(animal.hasOwnProperty); // undefined\n\n// But you can still add and access custom properties\nanimal.describe = function () {\n console.log(\\`Name of the animal is \\${this.name}\\`);\n};\n\nanimal.describe(); // \"Name of the animal is Rocky\"\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u8D44\\u6E90\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain\",children:\"Inheritance and the prototype chain | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://dev.to/lydiahallie/javascript-visualized-prototypal-inheritance-47co\",children:\"JavaScript Visualized: Prototypal Inheritance\"})}),`\n`]})]})}function O(o={}){let{wrapper:e}=o.components||{};return e?(0,n.jsx)(e,Object.assign({},o,{children:(0,n.jsx)(d,o)})):d(o)}var w=O;return j(v);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var y=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var g=(o,e)=>()=>(e||o((e={exports:{}}).exports,e),e.exports),f=(o,e)=>{for(var t in e)c(o,t,{get:e[t],enumerable:!0})},i=(o,e,t,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!u.call(o,r)&&r!==t&&c(o,r,{get:()=>e[r],enumerable:!(a=p(e,r))||a.enumerable});return o};var b=(o,e,t)=>(t=o!=null?s(y(o)):{},i(e||!o||!o.__esModule?c(t,\"default\",{value:o,enumerable:!0}):t,o)),j=o=>i(c({},\"__esModule\",{value:!0}),o);var d=g((D,l)=>{l.exports=_jsx_runtime});var v={};f(v,{default:()=>P,frontmatter:()=>_});var n=b(d()),_={title:\"\\u89E3\\u91CA JavaScript \\u4E2D\\u539F\\u578B\\u7EE7\\u627F\\u7684\\u5DE5\\u4F5C\\u539F\\u7406\"};function h(o){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",a:\"a\",pre:\"pre\",ul:\"ul\",li:\"li\",hr:\"hr\",h3:\"h3\",ol:\"ol\",strong:\"strong\"},o.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"JavaScript \\u4E2D\\u7684\\u539F\\u578B\\u7EE7\\u627F\\u662F\\u5BF9\\u8C61\\u4ECE\\u5176\\u4ED6\\u5BF9\\u8C61\\u7EE7\\u627F\\u5C5E\\u6027\\u548C\\u65B9\\u6CD5\\u7684\\u4E00\\u79CD\\u65B9\\u5F0F\\u3002\\u6BCF\\u4E2A JavaScript \\u5BF9\\u8C61\\u90FD\\u6709\\u4E00\\u4E2A\\u540D\\u4E3A \",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\" \\u7684\\u7279\\u6B8A\\u9690\\u85CF\\u5C5E\\u6027\\uFF08\\u901A\\u5E38\\u901A\\u8FC7 \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" \\u6216\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Object.getPrototypeOf()\"}),\" \\u8BBF\\u95EE\\uFF09\\uFF0C\\u5B83\\u5F15\\u7528\\u53E6\\u4E00\\u4E2A\\u5BF9\\u8C61\\uFF0C\\u8BE5\\u5BF9\\u8C61\\u88AB\\u79F0\\u4E3A\\u5BF9\\u8C61\\u7684\\u201C\\u539F\\u578B\\u201D\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5F53\\u8BBF\\u95EE\\u5BF9\\u8C61\\u7684\\u5C5E\\u6027\\uFF0C\\u5E76\\u4E14\\u5728\\u8BE5\\u5BF9\\u8C61\\u4E0A\\u627E\\u4E0D\\u5230\\u8BE5\\u5C5E\\u6027\\u65F6\\uFF0CJavaScript \\u5F15\\u64CE\\u4F1A\\u67E5\\u770B\\u5BF9\\u8C61\\u7684 \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\"\\uFF0C\\u4EE5\\u53CA \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" \\u7684 \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\"\\uFF0C\\u4F9D\\u6B64\\u7C7B\\u63A8\\uFF0C\\u76F4\\u5230\\u5B83\\u5728\\u5176\\u4E2D\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" \\u4E0A\\u627E\\u5230\\u5B9A\\u4E49\\u7684\\u5C5E\\u6027\\uFF0C\\u6216\\u8005\\u76F4\\u5230\\u5B83\\u5230\\u8FBE\\u539F\\u578B\\u94FE\\u7684\\u672B\\u5C3E\\u3002\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8FD9\\u79CD\\u884C\\u4E3A\\u6A21\\u62DF\\u4E86\\u7ECF\\u5178\\u7EE7\\u627F\\uFF0C\\u4F46\\u5B9E\\u9645\\u4E0A\\u5B83\\u66F4\\u50CF\\u662F\",(0,n.jsx)(e.a,{href:\"https://davidwalsh.name/javascript-objects\",children:\"\\u59D4\\u6258\\u800C\\u4E0D\\u662F\\u7EE7\\u627F\"}),\"\\u3002\"]}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4EE5\\u4E0B\\u662F\\u539F\\u578B\\u7EE7\\u627F\\u7684\\u793A\\u4F8B\\uFF1A\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Parent object constructor.\nfunction Animal(name) {\n this.name = name;\n}\n\n// Add a method to the parent object's prototype.\nAnimal.prototype.makeSound = function () {\n console.log('The ' + this.constructor.name + ' makes a sound.');\n};\n\n// Child object constructor.\nfunction Dog(name) {\n Animal.call(this, name); // Call the parent constructor.\n}\n\n// Set the child object's prototype to be the parent's prototype.\nObject.setPrototypeOf(Dog.prototype, Animal.prototype);\n\n// Add a method to the child object's prototype.\nDog.prototype.bark = function () {\n console.log('Woof!');\n};\n\n// Create a new instance of Dog.\nconst bolt = new Dog('Bolt');\n\n// Call methods on the child object.\nconsole.log(bolt.name); // \"Bolt\"\nbolt.makeSound(); // \"The Dog makes a sound.\"\nbolt.bark(); // \"Woof!\"\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"\\u9700\\u8981\\u6CE8\\u610F\\u7684\\u662F\\uFF1A\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\".makeSound\"}),\" \\u672A\\u5728 \",(0,n.jsx)(e.code,{children:\"Dog\"}),\" \\u4E0A\\u5B9A\\u4E49\\uFF0C\\u56E0\\u6B64 JavaScript \\u5F15\\u64CE\\u4F1A\\u5411\\u4E0A\\u67E5\\u627E\\u539F\\u578B\\u94FE\\uFF0C\\u5E76\\u5728\\u7EE7\\u627F\\u7684 \",(0,n.jsx)(e.code,{children:\"Animal\"}),\" \\u4E0A\\u627E\\u5230 \",(0,n.jsx)(e.code,{children:\".makeSound\"}),\"\\u3002\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"\\u4E0D\\u518D\\u63A8\\u8350\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"Object.create()\"}),\" \\u6765\\u6784\\u5EFA\\u7EE7\\u627F\\u94FE\\u3002\\u8BF7\\u6539\\u7528 \",(0,n.jsx)(e.code,{children:\"Object.setPrototypeOf()\"}),\"\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Javascript \\u4E2D\\u7684\\u539F\\u578B\\u7EE7\\u627F\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u539F\\u578B\\u7EE7\\u627F\\u662F JavaScript \\u4E2D\\u7528\\u4E8E\\u521B\\u5EFA\\u4ECE\\u5176\\u4ED6\\u5BF9\\u8C61\\u7EE7\\u627F\\u5C5E\\u6027\\u548C\\u65B9\\u6CD5\\u5BF9\\u8C61\\u7684\\u7279\\u6027\\u3002JavaScript \\u4F7F\\u7528\\u57FA\\u4E8E\\u539F\\u578B\\u7684\\u6A21\\u578B\\uFF0C\\u800C\\u4E0D\\u662F\\u57FA\\u4E8E\\u7C7B\\u7684\\u7EE7\\u627F\\u6A21\\u578B\\uFF0C\\u5BF9\\u8C61\\u53EF\\u4EE5\\u76F4\\u63A5\\u4ECE\\u5176\\u4ED6\\u5BF9\\u8C61\\u7EE7\\u627F\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5173\\u952E\\u6982\\u5FF5\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"\\u539F\\u578B\"}),\"\\uFF1AJavaScript \\u4E2D\\u7684\\u6BCF\\u4E2A\\u5BF9\\u8C61\\u90FD\\u6709\\u4E00\\u4E2A\\u539F\\u578B\\uFF0C\\u5B83\\u4E5F\\u662F\\u4E00\\u4E2A\\u5BF9\\u8C61\\u3002\\u5F53\\u60A8\\u4F7F\\u7528\\u5BF9\\u8C61\\u5B57\\u9762\\u91CF\\u6216\\u6784\\u9020\\u51FD\\u6570\\u521B\\u5EFA\\u5BF9\\u8C61\\u65F6\\uFF0C\\u65B0\\u5BF9\\u8C61\\u5C06\\u94FE\\u63A5\\u5230\\u5176\\u6784\\u9020\\u51FD\\u6570\\u7684\\u539F\\u578B\\uFF0C\\u5982\\u679C\\u672A\\u6307\\u5B9A\\u539F\\u578B\\uFF0C\\u5219\\u94FE\\u63A5\\u5230 \",(0,n.jsx)(e.code,{children:\"Object.prototype\"}),\"\\u3002\\u8FD9\\u901A\\u5E38\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"__proto__\"}),\" \\u6216 \",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\" \\u5F15\\u7528\\u3002\\u60A8\\u8FD8\\u53EF\\u4EE5\\u4F7F\\u7528\\u5185\\u7F6E\\u65B9\\u6CD5 \",(0,n.jsx)(e.code,{children:\"Object.getPrototypeOf()\"}),\" \\u83B7\\u53D6\\u539F\\u578B\\uFF0C\\u5E76\\u4E14\\u53EF\\u4EE5\\u901A\\u8FC7 \",(0,n.jsx)(e.code,{children:\"Object.setPrototypeOf()\"}),\" \\u8BBE\\u7F6E\\u5BF9\\u8C61\\u7684\\u539F\\u578B\\u3002\"]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Define a constructor function\nfunction Person(name, age) {\n this.name = name;\n this.age = age;\n}\n\n// Add a method to the prototype\nPerson.prototype.sayHello = function () {\n console.log(\\`Hello, my name is \\${this.name} and I am \\${this.age} years old.\\`);\n};\n\n// Create a new object using the constructor function\nlet john = new Person('John', 30);\n\n// The new object has access to the methods defined on the prototype\njohn.sayHello(); // \"Hello, my name is John and I am 30 years old.\"\n\n// The prototype of the new object is the prototype of the constructor function\nconsole.log(john.__proto__ === Person.prototype); // true\n\n// You can also get the prototype using Object.getPrototypeOf()\nconsole.log(Object.getPrototypeOf(john) === Person.prototype); // true\n\n// You can set the prototype of an object using Object.setPrototypeOf()\nlet newProto = {\n sayGoodbye: function () {\n console.log(\\`Goodbye, my name is \\${this.name}\\`);\n },\n};\n\nObject.setPrototypeOf(john, newProto);\n\n// Now john has access to the methods defined on the new prototype\njohn.sayGoodbye(); // \"Goodbye, my name is John\"\n\n// But no longer has access to the methods defined on the old prototype\nconsole.log(john.sayHello); // undefined\n`})}),`\n`,(0,n.jsxs)(e.ol,{start:\"2\",children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u539F\\u578B\\u94FE\"}),\"\\uFF1A\\u5F53\\u8BBF\\u95EE\\u5BF9\\u8C61\\u7684\\u5C5E\\u6027\\u6216\\u65B9\\u6CD5\\u65F6\\uFF0CJavaScript \\u9996\\u5148\\u5728\\u5BF9\\u8C61\\u672C\\u8EAB\\u4E0A\\u67E5\\u627E\\u5B83\\u3002\\u5982\\u679C\\u627E\\u4E0D\\u5230\\uFF0C\\u5B83\\u4F1A\\u67E5\\u770B\\u5BF9\\u8C61\\u7684\\u539F\\u578B\\uFF0C\\u7136\\u540E\\u662F\\u539F\\u578B\\u7684\\u539F\\u578B\\uFF0C\\u4F9D\\u6B64\\u7C7B\\u63A8\\uFF0C\\u76F4\\u5230\\u627E\\u5230\\u8BE5\\u5C5E\\u6027\\u6216\\u5230\\u8FBE\\u94FE\\u7684\\u672B\\u5C3E\\uFF08\\u5373 \",(0,n.jsx)(e.code,{children:\"null\"}),\"\\uFF09\\u3002\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"\\u6784\\u9020\\u51FD\\u6570\"}),\"\\uFF1AJavaScript \\u63D0\\u4F9B\\u4E86\\u6784\\u9020\\u51FD\\u6570\\u6765\\u521B\\u5EFA\\u5BF9\\u8C61\\u3002\\u5F53\\u4E00\\u4E2A\\u51FD\\u6570\\u4E0E new \\u5173\\u952E\\u5B57\\u4E00\\u8D77\\u7528\\u4F5C\\u6784\\u9020\\u51FD\\u6570\\u65F6\\uFF0C\\u65B0\\u5BF9\\u8C61\\u7684\\u539F\\u578B (\",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\") \\u5C06\\u8BBE\\u7F6E\\u4E3A\\u6784\\u9020\\u51FD\\u6570 \\u7684\\u539F\\u578B\\u5C5E\\u6027\\u3002\"]}),`\n`]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// \\u5B9A\\u4E49\\u4E00\\u4E2A\\u6784\\u9020\\u51FD\\u6570\nfunction Animal(name) {\n this.name = name;\n}\n\n// \\u5C06\\u4E00\\u4E2A\\u65B9\\u6CD5\\u6DFB\\u52A0\\u5230\\u539F\\u578B\\u4E0A\nAnimal.prototype.sayName = function () {\n console.log(\\`\\u6211\\u7684\\u540D\\u5B57\\u662F \\${this.name}\\`);\n};\n\n// \\u5B9A\\u4E49\\u4E00\\u4E2A\\u65B0\\u7684\\u6784\\u9020\\u51FD\\u6570\nfunction Dog(name, breed) {\n Animal.call(this, name);\n this.breed = breed;\n}\n\n// \\u8BBE\\u7F6E Dog \\u7684\\u539F\\u578B\\u4EE5\\u7EE7\\u627F\\u81EA Animal \\u7684\\u539F\\u578B\nObject.setPrototypeOf(Dog.prototype, Animal.prototype);\n\n// \\u5C06\\u4E00\\u4E2A\\u65B9\\u6CD5\\u6DFB\\u52A0\\u5230 Dog \\u7684\\u539F\\u578B\\u4E0A\nDog.prototype.bark = function () {\n console.log('\\u6C6A\\uFF01');\n};\n\n// \\u4F7F\\u7528 Dog \\u6784\\u9020\\u51FD\\u6570\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u5BF9\\u8C61\nlet fido = new Dog('Fido', 'Labrador');\n\n// \\u65B0\\u5BF9\\u8C61\\u53EF\\u4EE5\\u8BBF\\u95EE\\u5728\\u5176\\u81EA\\u8EAB\\u539F\\u578B\\u548C Animal \\u539F\\u578B\\u4E0A\\u5B9A\\u4E49\\u7684\\u65B9\\u6CD5\nfido.bark(); // \"\\u6C6A\\uFF01\"\nfido.sayName(); // \"\\u6211\\u7684\\u540D\\u5B57\\u662F Fido\"\n\n// \\u5982\\u679C\\u6211\\u4EEC\\u5C1D\\u8BD5\\u8BBF\\u95EE Dog \\u539F\\u578B\\u6216 Animal \\u539F\\u578B\\u4E0A\\u4E0D\\u5B58\\u5728\\u7684\\u65B9\\u6CD5\\uFF0CJavaScript \\u5C06\\u8FD4\\u56DE undefined\nconsole.log(fido.fly); // undefined\n`})}),`\n`,(0,n.jsxs)(e.ol,{start:\"4\",children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:(0,n.jsx)(e.code,{children:\"Object.create()\"})}),\": \\u6B64\\u65B9\\u6CD5\\u521B\\u5EFA\\u4E00\\u4E2A\\u65B0\\u5BF9\\u8C61\\uFF0C\\u5176\\u5185\\u90E8 \",(0,n.jsx)(e.code,{children:\"[[Prototype]]\"}),\" \\u76F4\\u63A5\\u94FE\\u63A5\\u5230\\u6307\\u5B9A\\u7684\\u539F\\u578B\\u5BF9\\u8C61\\u3002\\u8FD9\\u662F\\u521B\\u5EFA\\u4ECE\\u53E6\\u4E00\\u4E2A\\u7279\\u5B9A\\u5BF9\\u8C61\\u7EE7\\u627F\\u7684\\u5BF9\\u8C61\\u7684\\u6700\\u76F4\\u63A5\\u65B9\\u6CD5\\uFF0C\\u65E0\\u9700\\u6D89\\u53CA\\u6784\\u9020\\u51FD\\u6570\\u3002\\u5982\\u679C\\u901A\\u8FC7 \",(0,n.jsx)(e.code,{children:\"Object.create(null)\"}),\" \\u521B\\u5EFA\\u4E00\\u4E2A\\u5BF9\\u8C61\\uFF0C\\u5B83\\u5C06\\u4E0D\\u4F1A\\u4ECE \",(0,n.jsx)(e.code,{children:\"Object.prototype\"}),\" \\u7EE7\\u627F\\u4EFB\\u4F55\\u5C5E\\u6027\\u3002\\u8FD9\\u610F\\u5473\\u7740\\u8BE5\\u5BF9\\u8C61\\u5C06\\u6CA1\\u6709\\u4EFB\\u4F55\\u5185\\u7F6E\\u5C5E\\u6027\\u6216\\u65B9\\u6CD5\\uFF0C\\u5982 \",(0,n.jsx)(e.code,{children:\"toString()\"}),\"\\u3001\",(0,n.jsx)(e.code,{children:\"hasOwnProperty()\"}),\",\"]}),`\n`]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Define a prototype object\nlet proto = {\n greet: function () {\n console.log(\\`Hello, my name is \\${this.name}\\`);\n },\n};\n\n// Use \\`Object.create()\\` to create a new object with the specified prototype\nlet person = Object.create(proto);\nperson.name = 'John';\n\n// The new object has access to the methods defined on the prototype\nperson.greet(); // \"Hello, my name is John\"\n\n// Check if the object has a property\nconsole.log(person.hasOwnProperty('name')); // true\n\n// Create an object that does not inherit from Object.prototype\nlet animal = Object.create(null);\nanimal.name = 'Rocky';\n\n// The new object does not have any built-in properties or methods\nconsole.log(animal.toString); // undefined\nconsole.log(animal.hasOwnProperty); // undefined\n\n// But you can still add and access custom properties\nanimal.describe = function () {\n console.log(\\`Name of the animal is \\${this.name}\\`);\n};\n\nanimal.describe(); // \"Name of the animal is Rocky\"\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u8D44\\u6E90\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain\",children:\"Inheritance and the prototype chain | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://dev.to/lydiahallie/javascript-visualized-prototypal-inheritance-47co\",children:\"JavaScript Visualized: Prototypal Inheritance\"})}),`\n`]})]})}function O(o={}){let{wrapper:e}=o.components||{};return e?(0,n.jsx)(e,Object.assign({},o,{children:(0,n.jsx)(h,o)})):h(o)}var P=O;return j(v);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-one-way-data-flow-of-react-and-its-benefits/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-one-way-data-flow-of-react-and-its-benefits/locales/en-US.json
index 7596ca157..8d0a6a910 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-one-way-data-flow-of-react-and-its-benefits/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-one-way-data-flow-of-react-and-its-benefits/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain one-way data flow of React and its benefits",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-one-way-data-flow-of-react-and-its-benefits/en-US.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var a in e)i(t,a,{get:e[a],enumerable:!0})},c=(t,e,a,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of m(e))!u.call(t,o)&&o!==a&&i(t,o,{get:()=>e[o],enumerable:!(r=p(e,o))||r.enumerable});return t};var C=(t,e,a)=>(a=t!=null?s(f(t)):{},c(e||!t||!t.__esModule?i(a,\"default\",{value:t,enumerable:!0}):a,t)),b=t=>c(i({},\"__esModule\",{value:!0}),t);var h=g((D,d)=>{d.exports=_jsx_runtime});var R={};w(R,{default:()=>j,frontmatter:()=>y});var n=C(h()),y={title:\"Explain one-way data flow of React and its benefits\"};function l(t){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",code:\"code\",pre:\"pre\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"In React, one-way data flow means that data in a React application flows in a single direction, from parent components to child components. This makes the data flow predictable and easier to debug. The main benefits include improved maintainability, easier debugging, and better performance.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"One-way data flow of React and its benefits\"}),`\n`,(0,n.jsx)(e.h3,{children:\"What is one-way data flow?\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In React, one-way data flow refers to the concept where data flows in a single direction, from parent components to child components. This is achieved through the use of \",(0,n.jsx)(e.code,{children:\"props\"}),\". Parent components pass data to child components via \",(0,n.jsx)(e.code,{children:\"props\"}),\", and child components can only read these \",(0,n.jsx)(e.code,{children:\"props\"}),\" but cannot modify them. If a child component needs to communicate back to the parent, it does so by calling a function passed down from the parent as a prop.\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Example\"}),`\n`,(0,n.jsx)(e.p,{children:\"Here is a simple example to illustrate one-way data flow:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`// ParentComponent.jsx\nimport React, { useState } from 'react';\nimport ChildComponent from './ChildComponent';\n\nconst ParentComponent = () => {\n const [data, setData] = useState('Hello from Parent');\n\n const handleChange = (newData) => {\n setData(newData);\n };\n\n return (\n \n
{data} \n \n \n );\n};\n\nexport default ParentComponent;\n\n// ChildComponent.jsx\nimport React from 'react';\n\nconst ChildComponent = ({ data, onChange }) => {\n return (\n \n
{data}
\n
onChange('Hello from Child')}>Change Data \n
\n );\n};\n\nexport default ChildComponent;\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"In this example, \",(0,n.jsx)(e.code,{children:\"ParentComponent\"}),\" passes \",(0,n.jsx)(e.code,{children:\"data\"}),\" and \",(0,n.jsx)(e.code,{children:\"handleChange\"}),\" function to \",(0,n.jsx)(e.code,{children:\"ChildComponent\"}),\" via \",(0,n.jsx)(e.code,{children:\"props\"}),\". The \",(0,n.jsx)(e.code,{children:\"ChildComponent\"}),\" can read the \",(0,n.jsx)(e.code,{children:\"data\"}),\" and call \",(0,n.jsx)(e.code,{children:\"onChange\"}),\" to communicate back to the parent.\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Benefits of one-way data flow\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Improved maintainability\"}),`\n`,(0,n.jsx)(e.p,{children:\"One-way data flow makes the application structure more predictable and easier to understand. Since data flows in a single direction, it is easier to track how data changes over time, making the codebase more maintainable.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Easier debugging\"}),`\n`,(0,n.jsx)(e.p,{children:\"With one-way data flow, it is easier to pinpoint where a bug might be occurring. Since data can only flow from parent to child, you can trace the data flow and identify the source of the issue more quickly.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Better performance\"}),`\n`,(0,n.jsx)(e.p,{children:\"One-way data flow can lead to better performance because it reduces the complexity of data management. React's reconciliation algorithm can efficiently update the DOM by comparing the current state with the previous state, minimizing the number of updates required.\"}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/components-and-props.html\",children:\"React documentation on components and props\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/state-and-lifecycle.html\",children:\"React documentation on state and lifecycle\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/lifting-state-up.html\",children:\"React documentation on lifting state up\"})}),`\n`]})]})}function x(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var j=x;return b(R);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var g=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),w=(t,e)=>{for(var a in e)i(t,a,{get:e[a],enumerable:!0})},c=(t,e,a,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of m(e))!u.call(t,o)&&o!==a&&i(t,o,{get:()=>e[o],enumerable:!(r=p(e,o))||r.enumerable});return t};var C=(t,e,a)=>(a=t!=null?s(f(t)):{},c(e||!t||!t.__esModule?i(a,\"default\",{value:t,enumerable:!0}):a,t)),b=t=>c(i({},\"__esModule\",{value:!0}),t);var h=g((D,d)=>{d.exports=_jsx_runtime});var R={};w(R,{default:()=>v,frontmatter:()=>y});var n=C(h()),y={title:\"Explain one-way data flow of React and its benefits\"};function l(t){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",code:\"code\",pre:\"pre\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"In React, one-way data flow means that data in a React application flows in a single direction, from parent components to child components. This makes the data flow predictable and easier to debug. The main benefits include improved maintainability, easier debugging, and better performance.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"One-way data flow of React and its benefits\"}),`\n`,(0,n.jsx)(e.h3,{children:\"What is one-way data flow?\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In React, one-way data flow refers to the concept where data flows in a single direction, from parent components to child components. This is achieved through the use of \",(0,n.jsx)(e.code,{children:\"props\"}),\". Parent components pass data to child components via \",(0,n.jsx)(e.code,{children:\"props\"}),\", and child components can only read these \",(0,n.jsx)(e.code,{children:\"props\"}),\" but cannot modify them. If a child component needs to communicate back to the parent, it does so by calling a function passed down from the parent as a prop.\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Example\"}),`\n`,(0,n.jsx)(e.p,{children:\"Here is a simple example to illustrate one-way data flow:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`// ParentComponent.jsx\nimport React, { useState } from 'react';\nimport ChildComponent from './ChildComponent';\n\nconst ParentComponent = () => {\n const [data, setData] = useState('Hello from Parent');\n\n const handleChange = (newData) => {\n setData(newData);\n };\n\n return (\n \n
{data} \n \n \n );\n};\n\nexport default ParentComponent;\n\n// ChildComponent.jsx\nimport React from 'react';\n\nconst ChildComponent = ({ data, onChange }) => {\n return (\n \n
{data}
\n
onChange('Hello from Child')}>Change Data \n
\n );\n};\n\nexport default ChildComponent;\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"In this example, \",(0,n.jsx)(e.code,{children:\"ParentComponent\"}),\" passes \",(0,n.jsx)(e.code,{children:\"data\"}),\" and \",(0,n.jsx)(e.code,{children:\"handleChange\"}),\" function to \",(0,n.jsx)(e.code,{children:\"ChildComponent\"}),\" via \",(0,n.jsx)(e.code,{children:\"props\"}),\". The \",(0,n.jsx)(e.code,{children:\"ChildComponent\"}),\" can read the \",(0,n.jsx)(e.code,{children:\"data\"}),\" and call \",(0,n.jsx)(e.code,{children:\"onChange\"}),\" to communicate back to the parent.\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Benefits of one-way data flow\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Improved maintainability\"}),`\n`,(0,n.jsx)(e.p,{children:\"One-way data flow makes the application structure more predictable and easier to understand. Since data flows in a single direction, it is easier to track how data changes over time, making the codebase more maintainable.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Easier debugging\"}),`\n`,(0,n.jsx)(e.p,{children:\"With one-way data flow, it is easier to pinpoint where a bug might be occurring. Since data can only flow from parent to child, you can trace the data flow and identify the source of the issue more quickly.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Better performance\"}),`\n`,(0,n.jsx)(e.p,{children:\"One-way data flow can lead to better performance because it reduces the complexity of data management. React's reconciliation algorithm can efficiently update the DOM by comparing the current state with the previous state, minimizing the number of updates required.\"}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn/passing-props-to-a-component\",children:\"React documentation on components and props\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn/state-a-components-memory\",children:\"React documentation on state\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn/sharing-state-between-components\",children:\"React documentation on lifting state up\"})}),`\n`]})]})}function x(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var v=x;return b(R);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-one-way-data-flow-of-react-and-its-benefits/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-one-way-data-flow-of-react-and-its-benefits/locales/zh-CN.json
index 1059f1985..e2e53e8df 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-one-way-data-flow-of-react-and-its-benefits/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-one-way-data-flow-of-react-and-its-benefits/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释 React 的单向数据流及其优势",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-one-way-data-flow-of-react-and-its-benefits/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var p=Object.create;var c=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var g=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),f=(t,n)=>{for(var r in n)c(t,r,{get:n[r],enumerable:!0})},h=(t,n,r,a)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let o of m(n))!u.call(t,o)&&o!==r&&c(t,o,{get:()=>n[o],enumerable:!(a=s(n,o))||a.enumerable});return t};var x=(t,n,r)=>(r=t!=null?p(C(t)):{},h(n||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),j=t=>h(c({},\"__esModule\",{value:!0}),t);var l=g((v,d)=>{d.exports=_jsx_runtime});var P={};f(P,{default:()=>_,frontmatter:()=>R});var e=x(l()),R={title:\"\\u89E3\\u91CA React \\u7684\\u5355\\u5411\\u6570\\u636E\\u6D41\\u53CA\\u5176\\u4F18\\u52BF\"};function i(t){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",code:\"code\",pre:\"pre\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5728 React \\u4E2D\\uFF0C\\u5355\\u5411\\u6570\\u636E\\u6D41\\u610F\\u5473\\u7740 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u7684\\u6570\\u636E\\u4EE5\\u5355\\u4E2A\\u65B9\\u5411\\u6D41\\u52A8\\uFF0C\\u4ECE\\u7236\\u7EC4\\u4EF6\\u5230\\u5B50\\u7EC4\\u4EF6\\u3002\\u8FD9\\u4F7F\\u5F97\\u6570\\u636E\\u6D41\\u53EF\\u9884\\u6D4B\\u4E14\\u66F4\\u6613\\u4E8E\\u8C03\\u8BD5\\u3002\\u4E3B\\u8981\\u4F18\\u70B9\\u5305\\u62EC\\u63D0\\u9AD8\\u53EF\\u7EF4\\u62A4\\u6027\\u3001\\u66F4\\u6613\\u4E8E\\u8C03\\u8BD5\\u548C\\u66F4\\u597D\\u7684\\u6027\\u80FD\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"React \\u7684\\u5355\\u5411\\u6570\\u636E\\u6D41\\u53CA\\u5176\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EC0\\u4E48\\u662F\\u5355\\u5411\\u6570\\u636E\\u6D41\\uFF1F\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728 React \\u4E2D\\uFF0C\\u5355\\u5411\\u6570\\u636E\\u6D41\\u662F\\u6307\\u6570\\u636E\\u4EE5\\u5355\\u4E2A\\u65B9\\u5411\\u6D41\\u52A8\\uFF0C\\u4ECE\\u7236\\u7EC4\\u4EF6\\u5230\\u5B50\\u7EC4\\u4EF6\\u7684\\u6982\\u5FF5\\u3002\\u8FD9\\u662F\\u901A\\u8FC7\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"props\"}),\" \\u5B9E\\u73B0\\u7684\\u3002\\u7236\\u7EC4\\u4EF6\\u901A\\u8FC7 \",(0,e.jsx)(n.code,{children:\"props\"}),\" \\u5C06\\u6570\\u636E\\u4F20\\u9012\\u7ED9\\u5B50\\u7EC4\\u4EF6\\uFF0C\\u5B50\\u7EC4\\u4EF6\\u53EA\\u80FD\\u8BFB\\u53D6\\u8FD9\\u4E9B \",(0,e.jsx)(n.code,{children:\"props\"}),\"\\uFF0C\\u4F46\\u4E0D\\u80FD\\u4FEE\\u6539\\u5B83\\u4EEC\\u3002\\u5982\\u679C\\u5B50\\u7EC4\\u4EF6\\u9700\\u8981\\u53CD\\u9988\\u7ED9\\u7236\\u7EC4\\u4EF6\\uFF0C\\u5B83\\u4F1A\\u901A\\u8FC7\\u8C03\\u7528\\u4ECE\\u7236\\u7EC4\\u4EF6\\u4F5C\\u4E3A prop \\u4F20\\u9012\\u4E0B\\u6765\\u7684\\u51FD\\u6570\\u6765\\u5B9E\\u73B0\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u662F\\u4E00\\u4E2A\\u7B80\\u5355\\u7684\\u793A\\u4F8B\\uFF0C\\u7528\\u4E8E\\u8BF4\\u660E\\u5355\\u5411\\u6570\\u636E\\u6D41\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`// ParentComponent.jsx\nimport React, { useState } from 'react';\nimport ChildComponent from './ChildComponent';\n\nconst ParentComponent = () => {\n const [data, setData] = useState('Hello from Parent');\n\n const handleChange = (newData) => {\n setData(newData);\n };\n\n return (\n \n
{data} \n \n \n );\n};\n\nexport default ParentComponent;\n\n// ChildComponent.jsx\nimport React from 'react';\n\nconst ChildComponent = ({ data, onChange }) => {\n return (\n \n
{data}
\n
onChange('Hello from Child')}>Change Data \n
\n );\n};\n\nexport default ChildComponent;\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u6B64\\u793A\\u4F8B\\u4E2D\\uFF0C\",(0,e.jsx)(n.code,{children:\"ParentComponent\"}),\" \\u901A\\u8FC7 \",(0,e.jsx)(n.code,{children:\"props\"}),\" \\u5C06 \",(0,e.jsx)(n.code,{children:\"data\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"handleChange\"}),\" \\u51FD\\u6570\\u4F20\\u9012\\u7ED9 \",(0,e.jsx)(n.code,{children:\"ChildComponent\"}),\"\\u3002\",(0,e.jsx)(n.code,{children:\"ChildComponent\"}),\" \\u53EF\\u4EE5\\u8BFB\\u53D6 \",(0,e.jsx)(n.code,{children:\"data\"}),\" \\u5E76\\u8C03\\u7528 \",(0,e.jsx)(n.code,{children:\"onChange\"}),\" \\u4EE5\\u53CD\\u9988\\u7ED9\\u7236\\u7EC4\\u4EF6\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5355\\u5411\\u6570\\u636E\\u6D41\\u7684\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u63D0\\u9AD8\\u53EF\\u7EF4\\u62A4\\u6027\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5355\\u5411\\u6570\\u636E\\u6D41\\u4F7F\\u5E94\\u7528\\u7A0B\\u5E8F\\u7ED3\\u6784\\u66F4\\u5177\\u53EF\\u9884\\u6D4B\\u6027\\uFF0C\\u66F4\\u6613\\u4E8E\\u7406\\u89E3\\u3002\\u7531\\u4E8E\\u6570\\u636E\\u4EE5\\u5355\\u4E2A\\u65B9\\u5411\\u6D41\\u52A8\\uFF0C\\u56E0\\u6B64\\u66F4\\u5BB9\\u6613\\u8DDF\\u8E2A\\u6570\\u636E\\u968F\\u65F6\\u95F4\\u7684\\u53D8\\u5316\\uFF0C\\u4ECE\\u800C\\u4F7F\\u4EE3\\u7801\\u5E93\\u66F4\\u6613\\u4E8E\\u7EF4\\u62A4\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u66F4\\u6613\\u4E8E\\u8C03\\u8BD5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4F7F\\u7528\\u5355\\u5411\\u6570\\u636E\\u6D41\\uFF0C\\u66F4\\u5BB9\\u6613\\u67E5\\u660E\\u53EF\\u80FD\\u53D1\\u751F\\u9519\\u8BEF\\u7684\\u5730\\u70B9\\u3002\\u7531\\u4E8E\\u6570\\u636E\\u53EA\\u80FD\\u4ECE\\u7236\\u7EA7\\u6D41\\u5411\\u5B50\\u7EA7\\uFF0C\\u56E0\\u6B64\\u60A8\\u53EF\\u4EE5\\u8DDF\\u8E2A\\u6570\\u636E\\u6D41\\u5E76\\u66F4\\u5FEB\\u5730\\u786E\\u5B9A\\u95EE\\u9898\\u6765\\u6E90\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u66F4\\u597D\\u7684\\u6027\\u80FD\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5355\\u5411\\u6570\\u636E\\u6D41\\u53EF\\u4EE5\\u5E26\\u6765\\u66F4\\u597D\\u7684\\u6027\\u80FD\\uFF0C\\u56E0\\u4E3A\\u5B83\\u964D\\u4F4E\\u4E86\\u6570\\u636E\\u7BA1\\u7406\\u7684\\u590D\\u6742\\u6027\\u3002React \\u7684\\u534F\\u8C03\\u7B97\\u6CD5\\u53EF\\u4EE5\\u901A\\u8FC7\\u6BD4\\u8F83\\u5F53\\u524D\\u72B6\\u6001\\u548C\\u5148\\u524D\\u72B6\\u6001\\u6765\\u6709\\u6548\\u5730\\u66F4\\u65B0 DOM\\uFF0C\\u4ECE\\u800C\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u6240\\u9700\\u7684\\u66F4\\u65B0\\u6B21\\u6570\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/components-and-props.html\",children:\"React \\u7EC4\\u4EF6\\u548C props \\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/state-and-lifecycle.html\",children:\"React \\u72B6\\u6001\\u548C\\u751F\\u547D\\u5468\\u671F\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/lifting-state-up.html\",children:\"React \\u63D0\\u5347\\u72B6\\u6001\\u6587\\u6863\"})}),`\n`]})]})}function D(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(i,t)})):i(t)}var _=D;return j(P);})();\n;return Component;"
+ "solution": "var Component=(()=>{var p=Object.create;var a=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var g=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),f=(t,n)=>{for(var r in n)a(t,r,{get:n[r],enumerable:!0})},h=(t,n,r,c)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let o of m(n))!u.call(t,o)&&o!==r&&a(t,o,{get:()=>n[o],enumerable:!(c=s(n,o))||c.enumerable});return t};var x=(t,n,r)=>(r=t!=null?p(C(t)):{},h(n||!t||!t.__esModule?a(r,\"default\",{value:t,enumerable:!0}):r,t)),R=t=>h(a({},\"__esModule\",{value:!0}),t);var l=g((b,d)=>{d.exports=_jsx_runtime});var _={};f(_,{default:()=>v,frontmatter:()=>j});var e=x(l()),j={title:\"\\u89E3\\u91CA React \\u7684\\u5355\\u5411\\u6570\\u636E\\u6D41\\u53CA\\u5176\\u4F18\\u52BF\"};function i(t){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",code:\"code\",pre:\"pre\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5728 React \\u4E2D\\uFF0C\\u5355\\u5411\\u6570\\u636E\\u6D41\\u610F\\u5473\\u7740 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u7684\\u6570\\u636E\\u4EE5\\u5355\\u4E2A\\u65B9\\u5411\\u6D41\\u52A8\\uFF0C\\u4ECE\\u7236\\u7EC4\\u4EF6\\u5230\\u5B50\\u7EC4\\u4EF6\\u3002\\u8FD9\\u4F7F\\u5F97\\u6570\\u636E\\u6D41\\u53EF\\u9884\\u6D4B\\u4E14\\u66F4\\u6613\\u4E8E\\u8C03\\u8BD5\\u3002\\u4E3B\\u8981\\u4F18\\u70B9\\u5305\\u62EC\\u63D0\\u9AD8\\u53EF\\u7EF4\\u62A4\\u6027\\u3001\\u66F4\\u6613\\u4E8E\\u8C03\\u8BD5\\u548C\\u66F4\\u597D\\u7684\\u6027\\u80FD\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"React \\u7684\\u5355\\u5411\\u6570\\u636E\\u6D41\\u53CA\\u5176\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EC0\\u4E48\\u662F\\u5355\\u5411\\u6570\\u636E\\u6D41\\uFF1F\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728 React \\u4E2D\\uFF0C\\u5355\\u5411\\u6570\\u636E\\u6D41\\u662F\\u6307\\u6570\\u636E\\u4EE5\\u5355\\u4E2A\\u65B9\\u5411\\u6D41\\u52A8\\uFF0C\\u4ECE\\u7236\\u7EC4\\u4EF6\\u5230\\u5B50\\u7EC4\\u4EF6\\u7684\\u6982\\u5FF5\\u3002\\u8FD9\\u662F\\u901A\\u8FC7\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"props\"}),\" \\u5B9E\\u73B0\\u7684\\u3002\\u7236\\u7EC4\\u4EF6\\u901A\\u8FC7 \",(0,e.jsx)(n.code,{children:\"props\"}),\" \\u5C06\\u6570\\u636E\\u4F20\\u9012\\u7ED9\\u5B50\\u7EC4\\u4EF6\\uFF0C\\u5B50\\u7EC4\\u4EF6\\u53EA\\u80FD\\u8BFB\\u53D6\\u8FD9\\u4E9B \",(0,e.jsx)(n.code,{children:\"props\"}),\"\\uFF0C\\u4F46\\u4E0D\\u80FD\\u4FEE\\u6539\\u5B83\\u4EEC\\u3002\\u5982\\u679C\\u5B50\\u7EC4\\u4EF6\\u9700\\u8981\\u53CD\\u9988\\u7ED9\\u7236\\u7EC4\\u4EF6\\uFF0C\\u5B83\\u4F1A\\u901A\\u8FC7\\u8C03\\u7528\\u4ECE\\u7236\\u7EC4\\u4EF6\\u4F5C\\u4E3A prop \\u4F20\\u9012\\u4E0B\\u6765\\u7684\\u51FD\\u6570\\u6765\\u5B9E\\u73B0\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u662F\\u4E00\\u4E2A\\u7B80\\u5355\\u7684\\u793A\\u4F8B\\uFF0C\\u7528\\u4E8E\\u8BF4\\u660E\\u5355\\u5411\\u6570\\u636E\\u6D41\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`// ParentComponent.jsx\nimport React, { useState } from 'react';\nimport ChildComponent from './ChildComponent';\n\nconst ParentComponent = () => {\n const [data, setData] = useState('Hello from Parent');\n\n const handleChange = (newData) => {\n setData(newData);\n };\n\n return (\n \n
{data} \n \n \n );\n};\n\nexport default ParentComponent;\n\n// ChildComponent.jsx\nimport React from 'react';\n\nconst ChildComponent = ({ data, onChange }) => {\n return (\n \n
{data}
\n
onChange('Hello from Child')}>Change Data \n
\n );\n};\n\nexport default ChildComponent;\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u6B64\\u793A\\u4F8B\\u4E2D\\uFF0C\",(0,e.jsx)(n.code,{children:\"ParentComponent\"}),\" \\u901A\\u8FC7 \",(0,e.jsx)(n.code,{children:\"props\"}),\" \\u5C06 \",(0,e.jsx)(n.code,{children:\"data\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"handleChange\"}),\" \\u51FD\\u6570\\u4F20\\u9012\\u7ED9 \",(0,e.jsx)(n.code,{children:\"ChildComponent\"}),\"\\u3002\",(0,e.jsx)(n.code,{children:\"ChildComponent\"}),\" \\u53EF\\u4EE5\\u8BFB\\u53D6 \",(0,e.jsx)(n.code,{children:\"data\"}),\" \\u5E76\\u8C03\\u7528 \",(0,e.jsx)(n.code,{children:\"onChange\"}),\" \\u4EE5\\u53CD\\u9988\\u7ED9\\u7236\\u7EC4\\u4EF6\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5355\\u5411\\u6570\\u636E\\u6D41\\u7684\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u63D0\\u9AD8\\u53EF\\u7EF4\\u62A4\\u6027\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5355\\u5411\\u6570\\u636E\\u6D41\\u4F7F\\u5E94\\u7528\\u7A0B\\u5E8F\\u7ED3\\u6784\\u66F4\\u5177\\u53EF\\u9884\\u6D4B\\u6027\\uFF0C\\u66F4\\u6613\\u4E8E\\u7406\\u89E3\\u3002\\u7531\\u4E8E\\u6570\\u636E\\u4EE5\\u5355\\u4E2A\\u65B9\\u5411\\u6D41\\u52A8\\uFF0C\\u56E0\\u6B64\\u66F4\\u5BB9\\u6613\\u8DDF\\u8E2A\\u6570\\u636E\\u968F\\u65F6\\u95F4\\u7684\\u53D8\\u5316\\uFF0C\\u4ECE\\u800C\\u4F7F\\u4EE3\\u7801\\u5E93\\u66F4\\u6613\\u4E8E\\u7EF4\\u62A4\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u66F4\\u6613\\u4E8E\\u8C03\\u8BD5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4F7F\\u7528\\u5355\\u5411\\u6570\\u636E\\u6D41\\uFF0C\\u66F4\\u5BB9\\u6613\\u67E5\\u660E\\u53EF\\u80FD\\u53D1\\u751F\\u9519\\u8BEF\\u7684\\u5730\\u70B9\\u3002\\u7531\\u4E8E\\u6570\\u636E\\u53EA\\u80FD\\u4ECE\\u7236\\u7EA7\\u6D41\\u5411\\u5B50\\u7EA7\\uFF0C\\u56E0\\u6B64\\u60A8\\u53EF\\u4EE5\\u8DDF\\u8E2A\\u6570\\u636E\\u6D41\\u5E76\\u66F4\\u5FEB\\u5730\\u786E\\u5B9A\\u95EE\\u9898\\u6765\\u6E90\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u66F4\\u597D\\u7684\\u6027\\u80FD\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5355\\u5411\\u6570\\u636E\\u6D41\\u53EF\\u4EE5\\u5E26\\u6765\\u66F4\\u597D\\u7684\\u6027\\u80FD\\uFF0C\\u56E0\\u4E3A\\u5B83\\u964D\\u4F4E\\u4E86\\u6570\\u636E\\u7BA1\\u7406\\u7684\\u590D\\u6742\\u6027\\u3002React \\u7684\\u534F\\u8C03\\u7B97\\u6CD5\\u53EF\\u4EE5\\u901A\\u8FC7\\u6BD4\\u8F83\\u5F53\\u524D\\u72B6\\u6001\\u548C\\u5148\\u524D\\u72B6\\u6001\\u6765\\u6709\\u6548\\u5730\\u66F4\\u65B0 DOM\\uFF0C\\u4ECE\\u800C\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u6240\\u9700\\u7684\\u66F4\\u65B0\\u6B21\\u6570\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/learn/passing-props-to-a-component\",children:\"React \\u7EC4\\u4EF6\\u548C Props \\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/learn/state-a-components-memory\",children:\"React \\u72B6\\u6001\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/learn/sharing-state-between-components\",children:\"React \\u63D0\\u5347\\u72B6\\u6001\\u6587\\u6863\"})}),`\n`]})]})}function D(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(i,t)})):i(t)}var v=D;return R(_);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-server-side-rendering-of-react-applications-and-its-benefits/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-server-side-rendering-of-react-applications-and-its-benefits/locales/en-US.json
index c7b9012ab..e272ddc03 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-server-side-rendering-of-react-applications-and-its-benefits/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-server-side-rendering-of-react-applications-and-its-benefits/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain server-side rendering of React applications and its benefits?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-server-side-rendering-of-react-applications-and-its-benefits/en-US.mdx"
},
- "solution": "var Component=(()=>{var l=Object.create;var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var v=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),f=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},o=(r,e,t,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of g(e))!m.call(r,i)&&i!==t&&s(r,i,{get:()=>e[i],enumerable:!(a=p(e,i))||a.enumerable});return r};var S=(r,e,t)=>(t=r!=null?l(u(r)):{},o(e||!r||!r.__esModule?s(t,\"default\",{value:r,enumerable:!0}):t,r)),R=r=>o(s({},\"__esModule\",{value:!0}),r);var d=v((H,c)=>{c.exports=_jsx_runtime});var b={};f(b,{default:()=>T,frontmatter:()=>x});var n=S(d()),x={title:\"Explain server-side rendering of React applications and its benefits?\"};function h(r){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",code:\"code\",pre:\"pre\",ul:\"ul\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"Server-side rendering (SSR) in React involves rendering React components on the server and sending the fully rendered HTML to the client. This approach improves initial load times and SEO. The server handles the initial rendering, and the client takes over with React's hydration process. Benefits include faster initial page loads, better SEO, and improved performance on slower devices.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"What is server-side rendering of React applications?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Definition\"}),`\n`,(0,n.jsx)(e.p,{children:\"Server-side rendering (SSR) is a technique where the server renders the initial HTML of a React application and sends it to the client. This is in contrast to client-side rendering (CSR), where the browser downloads a minimal HTML page and renders the content using JavaScript.\"}),`\n`,(0,n.jsx)(e.h3,{children:\"How it works\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Initial request\"}),\": When a user requests a page, the server processes this request.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Rendering on the server\"}),\": The server uses React to render the components into HTML.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Sending HTML to the client\"}),\": The server sends the fully rendered HTML to the client.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Hydration\"}),\": Once the HTML is loaded, React takes over and binds the event handlers, making the page interactive.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Code example\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Here's a basic example using \",(0,n.jsx)(e.code,{children:\"Next.js\"}),\", a popular React framework that supports SSR out of the box:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import React from 'react';\n\nconst Home = ({ data }) => (\n \n
Welcome to my SSR React App \n
Data from server: {data}
\n
\n);\n\nexport async function getServerSideProps() {\n // Fetch data from an API or database\n const data = await fetchDataFromAPI();\n return { props: { data } };\n}\n\nexport default Home;\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Benefits of server-side rendering\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Improved initial load time\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Faster content display\"}),\": Since the server sends fully rendered HTML, users see the content faster compared to CSR, where the browser has to download and execute JavaScript before rendering.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Better SEO\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Search engine indexing\"}),\": Search engines can easily index the fully rendered HTML, improving the SEO of your application. This is particularly important for content-heavy sites.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Performance on slower devices\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Reduced client-side processing\"}),\": SSR reduces the amount of JavaScript that needs to be processed on the client side, which is beneficial for users with slower devices or poor network conditions.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Enhanced user experience\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Perceived performance\"}),\": Users perceive the application as faster because they see content sooner, even if the JavaScript is still loading in the background.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://nextjs.org/docs\",children:\"Next.js Documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/react-server.html\",children:\"React Server Components\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/react-dom-server.html\",children:\"Server-side rendering in React\"})}),`\n`]})]})}function w(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(h,r)})):h(r)}var T=w;return R(b);})();\n;return Component;"
+ "solution": "var Component=(()=>{var l=Object.create;var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var f=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),m=(r,e)=>{for(var t in e)s(r,t,{get:e[t],enumerable:!0})},c=(r,e,t,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of u(e))!v.call(r,i)&&i!==t&&s(r,i,{get:()=>e[i],enumerable:!(a=p(e,i))||a.enumerable});return r};var S=(r,e,t)=>(t=r!=null?l(g(r)):{},c(e||!r||!r.__esModule?s(t,\"default\",{value:r,enumerable:!0}):t,r)),R=r=>c(s({},\"__esModule\",{value:!0}),r);var d=f((H,o)=>{o.exports=_jsx_runtime});var b={};m(b,{default:()=>T,frontmatter:()=>x});var n=S(d()),x={title:\"Explain server-side rendering of React applications and its benefits?\"};function h(r){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",code:\"code\",pre:\"pre\",ul:\"ul\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"Server-side rendering (SSR) in React involves rendering React components on the server and sending the fully rendered HTML to the client. This approach improves initial load times and SEO. The server handles the initial rendering, and the client takes over with React's hydration process. Benefits include faster initial page loads, better SEO, and improved performance on slower devices.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"What is server-side rendering of React applications?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Definition\"}),`\n`,(0,n.jsx)(e.p,{children:\"Server-side rendering (SSR) is a technique where the server renders the initial HTML of a React application and sends it to the client. This is in contrast to client-side rendering (CSR), where the browser downloads a minimal HTML page and renders the content using JavaScript.\"}),`\n`,(0,n.jsx)(e.h3,{children:\"How it works\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Initial request\"}),\": When a user requests a page, the server processes this request.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Rendering on the server\"}),\": The server uses React to render the components into HTML.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Sending HTML to the client\"}),\": The server sends the fully rendered HTML to the client.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Hydration\"}),\": Once the HTML is loaded, React takes over and binds the event handlers, making the page interactive.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Code example\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Here's a basic example using \",(0,n.jsx)(e.code,{children:\"Next.js\"}),\", a popular React framework that supports SSR out of the box:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import React from 'react';\n\nconst Home = ({ data }) => (\n \n
Welcome to my SSR React App \n
Data from server: {data}
\n
\n);\n\nexport async function getServerSideProps() {\n // Fetch data from an API or database\n const data = await fetchDataFromAPI();\n return { props: { data } };\n}\n\nexport default Home;\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Benefits of server-side rendering\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Improved initial load time\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Faster content display\"}),\": Since the server sends fully rendered HTML, users see the content faster compared to CSR, where the browser has to download and execute JavaScript before rendering.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Better SEO\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Search engine indexing\"}),\": Search engines can easily index the fully rendered HTML, improving the SEO of your application. This is particularly important for content-heavy sites.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Performance on slower devices\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Reduced client-side processing\"}),\": SSR reduces the amount of JavaScript that needs to be processed on the client side, which is beneficial for users with slower devices or poor network conditions.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Enhanced user experience\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Perceived performance\"}),\": Users perceive the application as faster because they see content sooner, even if the JavaScript is still loading in the background.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://nextjs.org/docs\",children:\"Next.js Documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/reference/rsc/server-components\",children:\"React Server Components\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/reference/react-dom/server\",children:\"Server-side rendering in React\"})}),`\n`]})]})}function w(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(h,r)})):h(r)}var T=w;return R(b);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-server-side-rendering-of-react-applications-and-its-benefits/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-server-side-rendering-of-react-applications-and-its-benefits/locales/zh-CN.json
index 419cdfbef..665909a5d 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-server-side-rendering-of-react-applications-and-its-benefits/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-server-side-rendering-of-react-applications-and-its-benefits/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释 React 应用程序的服务器端渲染及其优势?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-server-side-rendering-of-react-applications-and-its-benefits/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var u=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),m=(r,n)=>{for(var c in n)i(r,c,{get:n[c],enumerable:!0})},h=(r,n,c,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of S(n))!g.call(r,t)&&t!==c&&i(r,t,{get:()=>n[t],enumerable:!(l=p(n,t))||l.enumerable});return r};var x=(r,n,c)=>(c=r!=null?s(R(r)):{},h(n||!r||!r.__esModule?i(c,\"default\",{value:r,enumerable:!0}):c,r)),M=r=>h(i({},\"__esModule\",{value:!0}),r);var a=u((T,d)=>{d.exports=_jsx_runtime});var L={};m(L,{default:()=>j,frontmatter:()=>H});var e=x(a()),H={title:\"\\u89E3\\u91CA React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u53CA\\u5176\\u4F18\\u52BF\\uFF1F\"};function o(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",code:\"code\",pre:\"pre\",ul:\"ul\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"\\u603B\\u7ED3\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u4E2D\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3 (SSR) \\u6D89\\u53CA\\u5728\\u670D\\u52A1\\u5668\\u4E0A\\u6E32\\u67D3 React \\u7EC4\\u4EF6\\uFF0C\\u5E76\\u5C06\\u5B8C\\u5168\\u6E32\\u67D3\\u7684 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u53EF\\u4EE5\\u6539\\u5584\\u521D\\u59CB\\u52A0\\u8F7D\\u65F6\\u95F4\\u548C SEO\\u3002\\u670D\\u52A1\\u5668\\u5904\\u7406\\u521D\\u59CB\\u6E32\\u67D3\\uFF0C\\u5BA2\\u6237\\u7AEF\\u901A\\u8FC7 React \\u7684\\u6C34\\u5408\\u8FC7\\u7A0B\\u63A5\\u7BA1\\u3002\\u597D\\u5904\\u5305\\u62EC\\u66F4\\u5FEB\\u7684\\u521D\\u59CB\\u9875\\u9762\\u52A0\\u8F7D\\u3001\\u66F4\\u597D\\u7684 SEO \\u4EE5\\u53CA\\u5728\\u8F83\\u6162\\u8BBE\\u5907\\u4E0A\\u7684\\u6539\\u8FDB\\u6027\\u80FD\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4EC0\\u4E48\\u662F React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\uFF1F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5B9A\\u4E49\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3 (SSR) \\u662F\\u4E00\\u79CD\\u6280\\u672F\\uFF0C\\u670D\\u52A1\\u5668\\u6E32\\u67D3 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u521D\\u59CB HTML \\u5E76\\u5C06\\u5176\\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u3002\\u8FD9\\u4E0E\\u5BA2\\u6237\\u7AEF\\u6E32\\u67D3 (CSR) \\u5F62\\u6210\\u5BF9\\u6BD4\\uFF0C\\u5728\\u5BA2\\u6237\\u7AEF\\u6E32\\u67D3\\u4E2D\\uFF0C\\u6D4F\\u89C8\\u5668\\u4E0B\\u8F7D\\u4E00\\u4E2A\\u6700\\u5C0F\\u7684 HTML \\u9875\\u9762\\uFF0C\\u5E76\\u4F7F\\u7528 JavaScript \\u6E32\\u67D3\\u5185\\u5BB9\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5DE5\\u4F5C\\u539F\\u7406\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u521D\\u59CB\\u8BF7\\u6C42\"}),\"\\uFF1A\\u5F53\\u7528\\u6237\\u8BF7\\u6C42\\u9875\\u9762\\u65F6\\uFF0C\\u670D\\u52A1\\u5668\\u5904\\u7406\\u6B64\\u8BF7\\u6C42\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5728\\u670D\\u52A1\\u5668\\u4E0A\\u6E32\\u67D3\"}),\"\\uFF1A\\u670D\\u52A1\\u5668\\u4F7F\\u7528 React \\u5C06\\u7EC4\\u4EF6\\u6E32\\u67D3\\u6210 HTML\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5C06 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\"}),\"\\uFF1A\\u670D\\u52A1\\u5668\\u5C06\\u5B8C\\u5168\\u6E32\\u67D3\\u7684 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6C34\\u5408\"}),\"\\uFF1A\\u52A0\\u8F7D HTML \\u540E\\uFF0CReact \\u63A5\\u7BA1\\u5E76\\u7ED1\\u5B9A\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\uFF0C\\u4F7F\\u9875\\u9762\\u5177\\u6709\\u4EA4\\u4E92\\u6027\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EE3\\u7801\\u793A\\u4F8B\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u8FD9\\u662F\\u4E00\\u4E2A\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"Next.js\"}),\" \\u7684\\u57FA\\u672C\\u793A\\u4F8B\\uFF0C\\u8FD9\\u662F\\u4E00\\u4E2A\\u652F\\u6301\\u5F00\\u7BB1\\u5373\\u7528\\u7684 SSR \\u7684\\u6D41\\u884C React \\u6846\\u67B6\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import React from 'react';\n\nconst Home = ({ data }) => (\n \n
\\u6B22\\u8FCE\\u6765\\u5230\\u6211\\u7684 SSR React \\u5E94\\u7528\\u7A0B\\u5E8F \n
\\u6765\\u81EA\\u670D\\u52A1\\u5668\\u7684\\u6570\\u636E\\uFF1A{data}
\n
\n);\n\nexport async function getServerSideProps() {\n // \\u4ECE API \\u6216\\u6570\\u636E\\u5E93\\u4E2D\\u83B7\\u53D6\\u6570\\u636E\n const data = await fetchDataFromAPI();\n return { props: { data } };\n}\n\nexport default Home;\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u7684\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6539\\u8FDB\\u7684\\u521D\\u59CB\\u52A0\\u8F7D\\u65F6\\u95F4\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u66F4\\u5FEB\\u7684\\u5185\\u5BB9\\u663E\\u793A\"}),\"\\uFF1A\\u7531\\u4E8E\\u670D\\u52A1\\u5668\\u53D1\\u9001\\u5B8C\\u5168\\u6E32\\u67D3\\u7684 HTML\\uFF0C\\u7528\\u6237\\u770B\\u5230\\u5185\\u5BB9\\u7684\\u663E\\u793A\\u901F\\u5EA6\\u6BD4 CSR \\u5FEB\\uFF0C\\u5728 CSR \\u4E2D\\uFF0C\\u6D4F\\u89C8\\u5668\\u5FC5\\u987B\\u5148\\u4E0B\\u8F7D\\u5E76\\u6267\\u884C JavaScript \\u624D\\u80FD\\u6E32\\u67D3\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u66F4\\u597D\\u7684 SEO\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u641C\\u7D22\\u5F15\\u64CE\\u7D22\\u5F15\"}),\"\\uFF1A\\u641C\\u7D22\\u5F15\\u64CE\\u53EF\\u4EE5\\u8F7B\\u677E\\u5730\\u7D22\\u5F15\\u5B8C\\u5168\\u6E32\\u67D3\\u7684 HTML\\uFF0C\\u4ECE\\u800C\\u6539\\u5584\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684 SEO\\u3002\\u8FD9\\u5BF9\\u4E8E\\u5185\\u5BB9\\u4E30\\u5BCC\\u7684\\u7F51\\u7AD9\\u5C24\\u5176\\u91CD\\u8981\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5728\\u8F83\\u6162\\u8BBE\\u5907\\u4E0A\\u7684\\u6027\\u80FD\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u51CF\\u5C11\\u5BA2\\u6237\\u7AEF\\u5904\\u7406\"}),\"\\uFF1ASSR \\u51CF\\u5C11\\u4E86\\u9700\\u8981\\u5728\\u5BA2\\u6237\\u7AEF\\u5904\\u7406\\u7684 JavaScript \\u91CF\\uFF0C\\u8FD9\\u5BF9\\u4E8E\\u4F7F\\u7528\\u8F83\\u6162\\u8BBE\\u5907\\u6216\\u7F51\\u7EDC\\u72B6\\u51B5\\u4E0D\\u4F73\\u7684\\u7528\\u6237\\u6765\\u8BF4\\u662F\\u6709\\u76CA\\u7684\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u589E\\u5F3A\\u7684\\u7528\\u6237\\u4F53\\u9A8C\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u611F\\u77E5\\u6027\\u80FD\"}),\"\\uFF1A\\u7528\\u6237\\u4F1A\\u89C9\\u5F97\\u5E94\\u7528\\u7A0B\\u5E8F\\u66F4\\u5FEB\\uFF0C\\u56E0\\u4E3A\\u4ED6\\u4EEC\\u53EF\\u4EE5\\u66F4\\u5FEB\\u5730\\u770B\\u5230\\u5185\\u5BB9\\uFF0C\\u5373\\u4F7F JavaScript \\u4ECD\\u5728\\u540E\\u53F0\\u52A0\\u8F7D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/react-dom-server.html\",children:\"React \\u4E2D\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\"})}),`\n`]})]})}function f(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(o,r)})):o(r)}var j=f;return M(L);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var u=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),m=(r,n)=>{for(var c in n)i(r,c,{get:n[c],enumerable:!0})},h=(r,n,c,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of S(n))!g.call(r,t)&&t!==c&&i(r,t,{get:()=>n[t],enumerable:!(l=p(n,t))||l.enumerable});return r};var f=(r,n,c)=>(c=r!=null?s(R(r)):{},h(n||!r||!r.__esModule?i(c,\"default\",{value:r,enumerable:!0}):c,r)),x=r=>h(i({},\"__esModule\",{value:!0}),r);var a=u((T,d)=>{d.exports=_jsx_runtime});var H={};m(H,{default:()=>j,frontmatter:()=>v});var e=f(a()),v={title:\"\\u89E3\\u91CA React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u53CA\\u5176\\u4F18\\u52BF\\uFF1F\"};function o(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",code:\"code\",pre:\"pre\",ul:\"ul\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"\\u603B\\u7ED3\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u4E2D\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3 (SSR) \\u6D89\\u53CA\\u5728\\u670D\\u52A1\\u5668\\u4E0A\\u6E32\\u67D3 React \\u7EC4\\u4EF6\\uFF0C\\u5E76\\u5C06\\u5B8C\\u5168\\u6E32\\u67D3\\u7684 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u3002\\u8FD9\\u79CD\\u65B9\\u6CD5\\u53EF\\u4EE5\\u6539\\u5584\\u521D\\u59CB\\u52A0\\u8F7D\\u65F6\\u95F4\\u548C SEO\\u3002\\u670D\\u52A1\\u5668\\u5904\\u7406\\u521D\\u59CB\\u6E32\\u67D3\\uFF0C\\u5BA2\\u6237\\u7AEF\\u901A\\u8FC7 React \\u7684\\u6C34\\u5408\\u8FC7\\u7A0B\\u63A5\\u7BA1\\u3002\\u597D\\u5904\\u5305\\u62EC\\u66F4\\u5FEB\\u7684\\u521D\\u59CB\\u9875\\u9762\\u52A0\\u8F7D\\u3001\\u66F4\\u597D\\u7684 SEO \\u4EE5\\u53CA\\u5728\\u8F83\\u6162\\u8BBE\\u5907\\u4E0A\\u7684\\u6539\\u8FDB\\u6027\\u80FD\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4EC0\\u4E48\\u662F React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\uFF1F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5B9A\\u4E49\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3 (SSR) \\u662F\\u4E00\\u79CD\\u6280\\u672F\\uFF0C\\u670D\\u52A1\\u5668\\u6E32\\u67D3 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u521D\\u59CB HTML \\u5E76\\u5C06\\u5176\\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u3002\\u8FD9\\u4E0E\\u5BA2\\u6237\\u7AEF\\u6E32\\u67D3 (CSR) \\u5F62\\u6210\\u5BF9\\u6BD4\\uFF0C\\u5728\\u5BA2\\u6237\\u7AEF\\u6E32\\u67D3\\u4E2D\\uFF0C\\u6D4F\\u89C8\\u5668\\u4E0B\\u8F7D\\u4E00\\u4E2A\\u6700\\u5C0F\\u7684 HTML \\u9875\\u9762\\uFF0C\\u5E76\\u4F7F\\u7528 JavaScript \\u6E32\\u67D3\\u5185\\u5BB9\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5DE5\\u4F5C\\u539F\\u7406\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u521D\\u59CB\\u8BF7\\u6C42\"}),\"\\uFF1A\\u5F53\\u7528\\u6237\\u8BF7\\u6C42\\u9875\\u9762\\u65F6\\uFF0C\\u670D\\u52A1\\u5668\\u5904\\u7406\\u6B64\\u8BF7\\u6C42\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5728\\u670D\\u52A1\\u5668\\u4E0A\\u6E32\\u67D3\"}),\"\\uFF1A\\u670D\\u52A1\\u5668\\u4F7F\\u7528 React \\u5C06\\u7EC4\\u4EF6\\u6E32\\u67D3\\u6210 HTML\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5C06 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\"}),\"\\uFF1A\\u670D\\u52A1\\u5668\\u5C06\\u5B8C\\u5168\\u6E32\\u67D3\\u7684 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6C34\\u5408\"}),\"\\uFF1A\\u52A0\\u8F7D HTML \\u540E\\uFF0CReact \\u63A5\\u7BA1\\u5E76\\u7ED1\\u5B9A\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\uFF0C\\u4F7F\\u9875\\u9762\\u5177\\u6709\\u4EA4\\u4E92\\u6027\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EE3\\u7801\\u793A\\u4F8B\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u8FD9\\u662F\\u4E00\\u4E2A\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"Next.js\"}),\" \\u7684\\u57FA\\u672C\\u793A\\u4F8B\\uFF0C\\u8FD9\\u662F\\u4E00\\u4E2A\\u652F\\u6301\\u5F00\\u7BB1\\u5373\\u7528\\u7684 SSR \\u7684\\u6D41\\u884C React \\u6846\\u67B6\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import React from 'react';\n\nconst Home = ({ data }) => (\n \n
\\u6B22\\u8FCE\\u6765\\u5230\\u6211\\u7684 SSR React \\u5E94\\u7528\\u7A0B\\u5E8F \n
\\u6765\\u81EA\\u670D\\u52A1\\u5668\\u7684\\u6570\\u636E\\uFF1A{data}
\n
\n);\n\nexport async function getServerSideProps() {\n // \\u4ECE API \\u6216\\u6570\\u636E\\u5E93\\u4E2D\\u83B7\\u53D6\\u6570\\u636E\n const data = await fetchDataFromAPI();\n return { props: { data } };\n}\n\nexport default Home;\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u7684\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6539\\u8FDB\\u7684\\u521D\\u59CB\\u52A0\\u8F7D\\u65F6\\u95F4\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u66F4\\u5FEB\\u7684\\u5185\\u5BB9\\u663E\\u793A\"}),\"\\uFF1A\\u7531\\u4E8E\\u670D\\u52A1\\u5668\\u53D1\\u9001\\u5B8C\\u5168\\u6E32\\u67D3\\u7684 HTML\\uFF0C\\u7528\\u6237\\u770B\\u5230\\u5185\\u5BB9\\u7684\\u663E\\u793A\\u901F\\u5EA6\\u6BD4 CSR \\u5FEB\\uFF0C\\u5728 CSR \\u4E2D\\uFF0C\\u6D4F\\u89C8\\u5668\\u5FC5\\u987B\\u5148\\u4E0B\\u8F7D\\u5E76\\u6267\\u884C JavaScript \\u624D\\u80FD\\u6E32\\u67D3\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u66F4\\u597D\\u7684 SEO\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u641C\\u7D22\\u5F15\\u64CE\\u7D22\\u5F15\"}),\"\\uFF1A\\u641C\\u7D22\\u5F15\\u64CE\\u53EF\\u4EE5\\u8F7B\\u677E\\u5730\\u7D22\\u5F15\\u5B8C\\u5168\\u6E32\\u67D3\\u7684 HTML\\uFF0C\\u4ECE\\u800C\\u6539\\u5584\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684 SEO\\u3002\\u8FD9\\u5BF9\\u4E8E\\u5185\\u5BB9\\u4E30\\u5BCC\\u7684\\u7F51\\u7AD9\\u5C24\\u5176\\u91CD\\u8981\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5728\\u8F83\\u6162\\u8BBE\\u5907\\u4E0A\\u7684\\u6027\\u80FD\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u51CF\\u5C11\\u5BA2\\u6237\\u7AEF\\u5904\\u7406\"}),\"\\uFF1ASSR \\u51CF\\u5C11\\u4E86\\u9700\\u8981\\u5728\\u5BA2\\u6237\\u7AEF\\u5904\\u7406\\u7684 JavaScript \\u91CF\\uFF0C\\u8FD9\\u5BF9\\u4E8E\\u4F7F\\u7528\\u8F83\\u6162\\u8BBE\\u5907\\u6216\\u7F51\\u7EDC\\u72B6\\u51B5\\u4E0D\\u4F73\\u7684\\u7528\\u6237\\u6765\\u8BF4\\u662F\\u6709\\u76CA\\u7684\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u589E\\u5F3A\\u7684\\u7528\\u6237\\u4F53\\u9A8C\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u611F\\u77E5\\u6027\\u80FD\"}),\"\\uFF1A\\u7528\\u6237\\u4F1A\\u89C9\\u5F97\\u5E94\\u7528\\u7A0B\\u5E8F\\u66F4\\u5FEB\\uFF0C\\u56E0\\u4E3A\\u4ED6\\u4EEC\\u53EF\\u4EE5\\u66F4\\u5FEB\\u5730\\u770B\\u5230\\u5185\\u5BB9\\uFF0C\\u5373\\u4F7F JavaScript \\u4ECD\\u5728\\u540E\\u53F0\\u52A0\\u8F7D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nextjs.org/docs\",children:\"Next.js \\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/reference/rsc/server-components\",children:\"React \\u670D\\u52A1\\u5668\\u7EC4\\u4EF6\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/reference/react-dom/server\",children:\"React \\u4E2D\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\"})}),`\n`]})]})}function M(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(o,r)})):o(r)}var j=M;return x(H);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-static-generation-of-react-applications-and-its-benefits/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-static-generation-of-react-applications-and-its-benefits/locales/en-US.json
index c1d3195f1..dbeaf2b99 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-static-generation-of-react-applications-and-its-benefits/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-static-generation-of-react-applications-and-its-benefits/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain static generation of React applications and its benefits?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-static-generation-of-react-applications-and-its-benefits/en-US.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),v=(t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:!0})},c=(t,e,i,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of p(e))!u.call(t,r)&&r!==i&&a(t,r,{get:()=>e[r],enumerable:!(s=g(e,r))||s.enumerable});return t};var b=(t,e,i)=>(i=t!=null?h(m(t)):{},c(e||!t||!t.__esModule?a(i,\"default\",{value:t,enumerable:!0}):i,t)),x=t=>c(a({},\"__esModule\",{value:!0}),t);var d=f((H,o)=>{o.exports=_jsx_runtime});var y={};v(y,{default:()=>j,frontmatter:()=>S});var n=b(d()),S={title:\"Explain static generation of React applications and its benefits?\"};function l(t){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",h4:\"h4\",ul:\"ul\",pre:\"pre\",code:\"code\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"Static generation in React applications involves pre-rendering the HTML at build time, rather than on each request. This results in faster load times and better performance since the HTML is already generated and can be served directly from a CDN. It also improves SEO and can reduce server load. Tools like Next.js facilitate static generation by allowing developers to generate static pages easily.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Static generation of React applications and its benefits\"}),`\n`,(0,n.jsx)(e.h3,{children:\"What is static generation?\"}),`\n`,(0,n.jsx)(e.p,{children:\"Static generation is a method of pre-rendering where the HTML of a page is generated at build time. This means that the HTML is created once, during the build process, and then reused for each request. In the context of React applications, this is often achieved using frameworks like Next.js.\"}),`\n`,(0,n.jsx)(e.h3,{children:\"How does static generation work?\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Build time rendering\"}),\": During the build process, the framework generates the HTML for each page based on the React components and data.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Static files\"}),\": The generated HTML, CSS, and JavaScript files are then stored as static files.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Serving the files\"}),\": These static files can be served directly from a CDN or a web server, without the need for server-side rendering on each request.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Benefits of static generation\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Improved performance\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Faster load times\"}),\": Since the HTML is pre-generated, it can be served immediately without waiting for server-side rendering.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Reduced server load\"}),\": Static files can be served from a CDN, reducing the load on the origin server.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Better SEO\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Search engine indexing\"}),\": Pre-rendered HTML is more easily indexed by search engines, improving SEO.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Consistent content\"}),\": The content is consistent across requests, ensuring that search engines see the same content as users.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Enhanced security\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"No server-side code execution\"}),\": Since there is no server-side rendering, there is less risk of server-side vulnerabilities.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Static files\"}),\": Serving static files reduces the attack surface compared to dynamic content generation.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Scalability\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"CDN distribution\"}),\": Static files can be distributed across multiple CDN nodes, improving scalability and reducing latency.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Efficient caching\"}),\": Static files can be easily cached, further improving performance and reducing server load.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Example with Next.js\"}),`\n`,(0,n.jsx)(e.p,{children:\"Next.js is a popular framework for React that supports static generation. Here is a simple example of how to use static generation in Next.js:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`// pages/index.js\nimport React from 'react';\n\nconst HomePage = ({ data }) => {\n return (\n \n
Welcome to my static site! \n
{data.message}
\n
\n );\n};\n\nexport async function getStaticProps() {\n // Fetch data at build time\n const data = { message: 'Hello, world!' };\n return {\n props: {\n data,\n },\n };\n}\n\nexport default HomePage;\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"In this example, the \",(0,n.jsx)(e.code,{children:\"getStaticProps\"}),\" function fetches data at build time, and the \",(0,n.jsx)(e.code,{children:\"HomePage\"}),\" component uses this data to render the HTML.\"]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://nextjs.org/docs/basic-features/pages#static-generation-recommended\",children:\"Next.js documentation on static generation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/getting-started.html\",children:\"React official documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://www.staticgen.com/\",children:\"Static site generators comparison\"})}),`\n`]})]})}function w(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var j=w;return x(y);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),v=(t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:!0})},c=(t,e,i,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of p(e))!m.call(t,r)&&r!==i&&a(t,r,{get:()=>e[r],enumerable:!(s=g(e,r))||s.enumerable});return t};var b=(t,e,i)=>(i=t!=null?h(u(t)):{},c(e||!t||!t.__esModule?a(i,\"default\",{value:t,enumerable:!0}):i,t)),x=t=>c(a({},\"__esModule\",{value:!0}),t);var d=f((H,o)=>{o.exports=_jsx_runtime});var j={};v(j,{default:()=>y,frontmatter:()=>S});var n=b(d()),S={title:\"Explain static generation of React applications and its benefits?\"};function l(t){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",h4:\"h4\",ul:\"ul\",pre:\"pre\",code:\"code\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"Static generation in React applications involves pre-rendering the HTML at build time, rather than on each request. This results in faster load times and better performance since the HTML is already generated and can be served directly from a CDN. It also improves SEO and can reduce server load. Tools like Next.js facilitate static generation by allowing developers to generate static pages easily.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Static generation of React applications and its benefits\"}),`\n`,(0,n.jsx)(e.h3,{children:\"What is static generation?\"}),`\n`,(0,n.jsx)(e.p,{children:\"Static generation is a method of pre-rendering where the HTML of a page is generated at build time. This means that the HTML is created once, during the build process, and then reused for each request. In the context of React applications, this is often achieved using frameworks like Next.js.\"}),`\n`,(0,n.jsx)(e.h3,{children:\"How does static generation work?\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Build time rendering\"}),\": During the build process, the framework generates the HTML for each page based on the React components and data.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Static files\"}),\": The generated HTML, CSS, and JavaScript files are then stored as static files.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Serving the files\"}),\": These static files can be served directly from a CDN or a web server, without the need for server-side rendering on each request.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Benefits of static generation\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Improved performance\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Faster load times\"}),\": Since the HTML is pre-generated, it can be served immediately without waiting for server-side rendering.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Reduced server load\"}),\": Static files can be served from a CDN, reducing the load on the origin server.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Better SEO\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Search engine indexing\"}),\": Pre-rendered HTML is more easily indexed by search engines, improving SEO.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Consistent content\"}),\": The content is consistent across requests, ensuring that search engines see the same content as users.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Enhanced security\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"No server-side code execution\"}),\": Since there is no server-side rendering, there is less risk of server-side vulnerabilities.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Static files\"}),\": Serving static files reduces the attack surface compared to dynamic content generation.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Scalability\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"CDN distribution\"}),\": Static files can be distributed across multiple CDN nodes, improving scalability and reducing latency.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Efficient caching\"}),\": Static files can be easily cached, further improving performance and reducing server load.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Example with Next.js\"}),`\n`,(0,n.jsx)(e.p,{children:\"Next.js is a popular framework for React that supports static generation. Here is a simple example of how to use static generation in Next.js:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`// pages/index.js\nimport React from 'react';\n\nconst HomePage = ({ data }) => {\n return (\n \n
Welcome to my static site! \n
{data.message}
\n
\n );\n};\n\nexport async function getStaticProps() {\n // Fetch data at build time\n const data = { message: 'Hello, world!' };\n return {\n props: {\n data,\n },\n };\n}\n\nexport default HomePage;\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"In this example, the \",(0,n.jsx)(e.code,{children:\"getStaticProps\"}),\" function fetches data at build time, and the \",(0,n.jsx)(e.code,{children:\"HomePage\"}),\" component uses this data to render the HTML.\"]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://nextjs.org/docs/basic-features/pages#static-generation-recommended\",children:\"Next.js documentation on static generation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn\",children:\"React official documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://www.staticgen.com/\",children:\"Static site generators comparison\"})}),`\n`]})]})}function w(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var y=w;return x(j);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-static-generation-of-react-applications-and-its-benefits/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-static-generation-of-react-applications-and-its-benefits/locales/zh-CN.json
index 1330d0ee6..07d960aa4 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-static-generation-of-react-applications-and-its-benefits/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-static-generation-of-react-applications-and-its-benefits/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释 React 应用程序的静态生成及其优势?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-static-generation-of-react-applications-and-its-benefits/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var o=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var x=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),j=(r,n)=>{for(var t in n)i(r,t,{get:n[t],enumerable:!0})},h=(r,n,t,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of p(n))!u.call(r,c)&&c!==t&&i(r,c,{get:()=>n[c],enumerable:!(l=g(n,c))||l.enumerable});return r};var f=(r,n,t)=>(t=r!=null?o(m(r)):{},h(n||!r||!r.__esModule?i(t,\"default\",{value:r,enumerable:!0}):t,r)),H=r=>h(i({},\"__esModule\",{value:!0}),r);var s=x((C,d)=>{d.exports=_jsx_runtime});var T={};j(T,{default:()=>L,frontmatter:()=>M});var e=f(s()),M={title:\"\\u89E3\\u91CA React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u9759\\u6001\\u751F\\u6210\\u53CA\\u5176\\u4F18\\u52BF\\uFF1F\"};function a(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",h4:\"h4\",ul:\"ul\",pre:\"pre\",code:\"code\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u7684\\u9759\\u6001\\u751F\\u6210\\u6D89\\u53CA\\u5728\\u6784\\u5EFA\\u65F6\\u9884\\u6E32\\u67D3 HTML\\uFF0C\\u800C\\u4E0D\\u662F\\u5728\\u6BCF\\u4E2A\\u8BF7\\u6C42\\u65F6\\u3002\\u8FD9\\u53EF\\u4EE5\\u52A0\\u5FEB\\u52A0\\u8F7D\\u65F6\\u95F4\\u5E76\\u63D0\\u9AD8\\u6027\\u80FD\\uFF0C\\u56E0\\u4E3A HTML \\u5DF2\\u7ECF\\u751F\\u6210\\uFF0C\\u53EF\\u4EE5\\u76F4\\u63A5\\u4ECE CDN \\u63D0\\u4F9B\\u3002\\u5B83\\u8FD8\\u53EF\\u4EE5\\u6539\\u5584 SEO \\u5E76\\u51CF\\u5C11\\u670D\\u52A1\\u5668\\u8D1F\\u8F7D\\u3002\\u50CF Next.js \\u8FD9\\u6837\\u7684\\u5DE5\\u5177\\u901A\\u8FC7\\u5141\\u8BB8\\u5F00\\u53D1\\u4EBA\\u5458\\u8F7B\\u677E\\u751F\\u6210\\u9759\\u6001\\u9875\\u9762\\u6765\\u4FC3\\u8FDB\\u9759\\u6001\\u751F\\u6210\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u9759\\u6001\\u751F\\u6210\\u53CA\\u5176\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EC0\\u4E48\\u662F\\u9759\\u6001\\u751F\\u6210\\uFF1F\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u9759\\u6001\\u751F\\u6210\\u662F\\u4E00\\u79CD\\u9884\\u6E32\\u67D3\\u65B9\\u6CD5\\uFF0C\\u5176\\u4E2D\\u9875\\u9762\\u7684 HTML \\u5728\\u6784\\u5EFA\\u65F6\\u751F\\u6210\\u3002\\u8FD9\\u610F\\u5473\\u7740 HTML \\u5728\\u6784\\u5EFA\\u8FC7\\u7A0B\\u4E2D\\u521B\\u5EFA\\u4E00\\u6B21\\uFF0C\\u7136\\u540E\\u5728\\u6BCF\\u4E2A\\u8BF7\\u6C42\\u4E2D\\u91CD\\u590D\\u4F7F\\u7528\\u3002\\u5728 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u4E0A\\u4E0B\\u6587\\u4E2D\\uFF0C\\u8FD9\\u901A\\u5E38\\u4F7F\\u7528 Next.js \\u7B49\\u6846\\u67B6\\u6765\\u5B9E\\u73B0\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u9759\\u6001\\u751F\\u6210\\u5982\\u4F55\\u5DE5\\u4F5C\\uFF1F\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6784\\u5EFA\\u65F6\\u6E32\\u67D3\"}),\"\\uFF1A\\u5728\\u6784\\u5EFA\\u8FC7\\u7A0B\\u4E2D\\uFF0C\\u6846\\u67B6\\u6839\\u636E React \\u7EC4\\u4EF6\\u548C\\u6570\\u636E\\u4E3A\\u6BCF\\u4E2A\\u9875\\u9762\\u751F\\u6210 HTML\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u9759\\u6001\\u6587\\u4EF6\"}),\"\\uFF1A\\u7136\\u540E\\uFF0C\\u751F\\u6210\\u7684 HTML\\u3001CSS \\u548C JavaScript \\u6587\\u4EF6\\u5C06\\u5B58\\u50A8\\u4E3A\\u9759\\u6001\\u6587\\u4EF6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u63D0\\u4F9B\\u6587\\u4EF6\"}),\"\\uFF1A\\u8FD9\\u4E9B\\u9759\\u6001\\u6587\\u4EF6\\u53EF\\u4EE5\\u76F4\\u63A5\\u4ECE CDN \\u6216 Web \\u670D\\u52A1\\u5668\\u63D0\\u4F9B\\uFF0C\\u800C\\u65E0\\u9700\\u5728\\u6BCF\\u4E2A\\u8BF7\\u6C42\\u4E0A\\u8FDB\\u884C\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u9759\\u6001\\u751F\\u6210\\u7684\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u63D0\\u9AD8\\u6027\\u80FD\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u66F4\\u5FEB\\u7684\\u52A0\\u8F7D\\u65F6\\u95F4\"}),\"\\uFF1A\\u7531\\u4E8E HTML \\u662F\\u9884\\u751F\\u6210\\u7684\\uFF0C\\u56E0\\u6B64\\u53EF\\u4EE5\\u7ACB\\u5373\\u63D0\\u4F9B\\uFF0C\\u800C\\u65E0\\u9700\\u7B49\\u5F85\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u51CF\\u5C11\\u670D\\u52A1\\u5668\\u8D1F\\u8F7D\"}),\"\\uFF1A\\u9759\\u6001\\u6587\\u4EF6\\u53EF\\u4EE5\\u4ECE CDN \\u63D0\\u4F9B\\uFF0C\\u4ECE\\u800C\\u51CF\\u5C11\\u4E86\\u6E90\\u670D\\u52A1\\u5668\\u7684\\u8D1F\\u8F7D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u66F4\\u597D\\u7684 SEO\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u641C\\u7D22\\u5F15\\u64CE\\u7D22\\u5F15\"}),\"\\uFF1A\\u9884\\u6E32\\u67D3\\u7684 HTML \\u66F4\\u5BB9\\u6613\\u88AB\\u641C\\u7D22\\u5F15\\u64CE\\u7D22\\u5F15\\uFF0C\\u4ECE\\u800C\\u6539\\u5584 SEO\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E00\\u81F4\\u7684\\u5185\\u5BB9\"}),\"\\uFF1A\\u5185\\u5BB9\\u5728\\u8BF7\\u6C42\\u4E4B\\u95F4\\u4FDD\\u6301\\u4E00\\u81F4\\uFF0C\\u786E\\u4FDD\\u641C\\u7D22\\u5F15\\u64CE\\u770B\\u5230\\u4E0E\\u7528\\u6237\\u76F8\\u540C\\u7684\\u5185\\u5BB9\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u589E\\u5F3A\\u5B89\\u5168\\u6027\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6CA1\\u6709\\u670D\\u52A1\\u5668\\u7AEF\\u4EE3\\u7801\\u6267\\u884C\"}),\"\\uFF1A\\u7531\\u4E8E\\u6CA1\\u6709\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\uFF0C\\u670D\\u52A1\\u5668\\u7AEF\\u6F0F\\u6D1E\\u7684\\u98CE\\u9669\\u8F83\\u5C0F\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u9759\\u6001\\u6587\\u4EF6\"}),\"\\uFF1A\\u63D0\\u4F9B\\u9759\\u6001\\u6587\\u4EF6\\u51CF\\u5C11\\u4E86\\u4E0E\\u52A8\\u6001\\u5185\\u5BB9\\u751F\\u6210\\u76F8\\u6BD4\\u7684\\u653B\\u51FB\\u9762\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u53EF\\u6269\\u5C55\\u6027\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"CDN \\u5206\\u53D1\"}),\"\\uFF1A\\u9759\\u6001\\u6587\\u4EF6\\u53EF\\u4EE5\\u5728\\u591A\\u4E2A CDN \\u8282\\u70B9\\u4E4B\\u95F4\\u5206\\u53D1\\uFF0C\\u4ECE\\u800C\\u63D0\\u9AD8\\u53EF\\u6269\\u5C55\\u6027\\u5E76\\u51CF\\u5C11\\u5EF6\\u8FDF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u9AD8\\u6548\\u7F13\\u5B58\"}),\"\\uFF1A\\u9759\\u6001\\u6587\\u4EF6\\u53EF\\u4EE5\\u8F7B\\u677E\\u7F13\\u5B58\\uFF0C\\u4ECE\\u800C\\u8FDB\\u4E00\\u6B65\\u63D0\\u9AD8\\u6027\\u80FD\\u5E76\\u51CF\\u5C11\\u670D\\u52A1\\u5668\\u8D1F\\u8F7D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Next.js \\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.p,{children:\"Next.js \\u662F\\u4E00\\u4E2A\\u6D41\\u884C\\u7684 React \\u6846\\u67B6\\uFF0C\\u652F\\u6301\\u9759\\u6001\\u751F\\u6210\\u3002\\u8FD9\\u662F\\u4E00\\u4E2A\\u5728 Next.js \\u4E2D\\u4F7F\\u7528\\u9759\\u6001\\u751F\\u6210\\u7684\\u7B80\\u5355\\u793A\\u4F8B\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`// pages/index.js\nimport React from 'react';\n\nconst HomePage = ({ data }) => {\n return (\n \n
\\u6B22\\u8FCE\\u6765\\u5230\\u6211\\u7684\\u9759\\u6001\\u7F51\\u7AD9\\uFF01 \n
{data.message}
\n
\n );\n};\n\nexport async function getStaticProps() {\n // \\u5728\\u6784\\u5EFA\\u65F6\\u83B7\\u53D6\\u6570\\u636E\n const data = { message: '\\u4F60\\u597D\\uFF0C\\u4E16\\u754C\\uFF01' };\n return {\n props: {\n data,\n },\n };\n}\n\nexport default HomePage;\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u8FD9\\u4E2A\\u4F8B\\u5B50\\u4E2D\\uFF0C\",(0,e.jsx)(n.code,{children:\"getStaticProps\"}),\" \\u51FD\\u6570\\u5728\\u6784\\u5EFA\\u65F6\\u83B7\\u53D6\\u6570\\u636E\\uFF0C\",(0,e.jsx)(n.code,{children:\"HomePage\"}),\" \\u7EC4\\u4EF6\\u4F7F\\u7528\\u8FD9\\u4E9B\\u6570\\u636E\\u6765\\u6E32\\u67D3 HTML\\u3002\"]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nextjs.org/docs/basic-features/pages#static-generation-recommended\",children:\"Next.js \\u5173\\u4E8E\\u9759\\u6001\\u751F\\u6210\\u7684\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/getting-started.html\",children:\"React \\u5B98\\u65B9\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://www.staticgen.com/\",children:\"\\u9759\\u6001\\u7F51\\u7AD9\\u751F\\u6210\\u5668\\u6BD4\\u8F83\"})}),`\n`]})]})}function N(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(a,r)})):a(r)}var L=N;return H(T);})();\n;return Component;"
+ "solution": "var Component=(()=>{var o=Object.create;var i=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var x=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),j=(r,n)=>{for(var c in n)i(r,c,{get:n[c],enumerable:!0})},h=(r,n,c,l)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of p(n))!u.call(r,t)&&t!==c&&i(r,t,{get:()=>n[t],enumerable:!(l=g(n,t))||l.enumerable});return r};var f=(r,n,c)=>(c=r!=null?o(m(r)):{},h(n||!r||!r.__esModule?i(c,\"default\",{value:r,enumerable:!0}):c,r)),H=r=>h(i({},\"__esModule\",{value:!0}),r);var s=x((C,d)=>{d.exports=_jsx_runtime});var T={};j(T,{default:()=>L,frontmatter:()=>M});var e=f(s()),M={title:\"\\u89E3\\u91CA React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u9759\\u6001\\u751F\\u6210\\u53CA\\u5176\\u4F18\\u52BF\\uFF1F\"};function a(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",h4:\"h4\",ul:\"ul\",pre:\"pre\",code:\"code\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u7684\\u9759\\u6001\\u751F\\u6210\\u6D89\\u53CA\\u5728\\u6784\\u5EFA\\u65F6\\u9884\\u6E32\\u67D3 HTML\\uFF0C\\u800C\\u4E0D\\u662F\\u5728\\u6BCF\\u4E2A\\u8BF7\\u6C42\\u65F6\\u3002\\u8FD9\\u53EF\\u4EE5\\u52A0\\u5FEB\\u52A0\\u8F7D\\u65F6\\u95F4\\u5E76\\u63D0\\u9AD8\\u6027\\u80FD\\uFF0C\\u56E0\\u4E3A HTML \\u5DF2\\u7ECF\\u751F\\u6210\\uFF0C\\u53EF\\u4EE5\\u76F4\\u63A5\\u4ECE CDN \\u63D0\\u4F9B\\u3002\\u5B83\\u8FD8\\u53EF\\u4EE5\\u6539\\u5584 SEO \\u5E76\\u51CF\\u5C11\\u670D\\u52A1\\u5668\\u8D1F\\u8F7D\\u3002\\u50CF Next.js \\u8FD9\\u6837\\u7684\\u5DE5\\u5177\\u901A\\u8FC7\\u5141\\u8BB8\\u5F00\\u53D1\\u4EBA\\u5458\\u8F7B\\u677E\\u751F\\u6210\\u9759\\u6001\\u9875\\u9762\\u6765\\u4FC3\\u8FDB\\u9759\\u6001\\u751F\\u6210\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u9759\\u6001\\u751F\\u6210\\u53CA\\u5176\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EC0\\u4E48\\u662F\\u9759\\u6001\\u751F\\u6210\\uFF1F\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u9759\\u6001\\u751F\\u6210\\u662F\\u4E00\\u79CD\\u9884\\u6E32\\u67D3\\u65B9\\u6CD5\\uFF0C\\u5176\\u4E2D\\u9875\\u9762\\u7684 HTML \\u5728\\u6784\\u5EFA\\u65F6\\u751F\\u6210\\u3002\\u8FD9\\u610F\\u5473\\u7740 HTML \\u5728\\u6784\\u5EFA\\u8FC7\\u7A0B\\u4E2D\\u521B\\u5EFA\\u4E00\\u6B21\\uFF0C\\u7136\\u540E\\u5728\\u6BCF\\u4E2A\\u8BF7\\u6C42\\u4E2D\\u91CD\\u590D\\u4F7F\\u7528\\u3002\\u5728 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u4E0A\\u4E0B\\u6587\\u4E2D\\uFF0C\\u8FD9\\u901A\\u5E38\\u4F7F\\u7528 Next.js \\u7B49\\u6846\\u67B6\\u6765\\u5B9E\\u73B0\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u9759\\u6001\\u751F\\u6210\\u5982\\u4F55\\u5DE5\\u4F5C\\uFF1F\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6784\\u5EFA\\u65F6\\u6E32\\u67D3\"}),\"\\uFF1A\\u5728\\u6784\\u5EFA\\u8FC7\\u7A0B\\u4E2D\\uFF0C\\u6846\\u67B6\\u6839\\u636E React \\u7EC4\\u4EF6\\u548C\\u6570\\u636E\\u4E3A\\u6BCF\\u4E2A\\u9875\\u9762\\u751F\\u6210 HTML\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u9759\\u6001\\u6587\\u4EF6\"}),\"\\uFF1A\\u7136\\u540E\\uFF0C\\u751F\\u6210\\u7684 HTML\\u3001CSS \\u548C JavaScript \\u6587\\u4EF6\\u5C06\\u5B58\\u50A8\\u4E3A\\u9759\\u6001\\u6587\\u4EF6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u63D0\\u4F9B\\u6587\\u4EF6\"}),\"\\uFF1A\\u8FD9\\u4E9B\\u9759\\u6001\\u6587\\u4EF6\\u53EF\\u4EE5\\u76F4\\u63A5\\u4ECE CDN \\u6216 Web \\u670D\\u52A1\\u5668\\u63D0\\u4F9B\\uFF0C\\u800C\\u65E0\\u9700\\u5728\\u6BCF\\u4E2A\\u8BF7\\u6C42\\u4E0A\\u8FDB\\u884C\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u9759\\u6001\\u751F\\u6210\\u7684\\u4F18\\u52BF\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u63D0\\u9AD8\\u6027\\u80FD\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u66F4\\u5FEB\\u7684\\u52A0\\u8F7D\\u65F6\\u95F4\"}),\"\\uFF1A\\u7531\\u4E8E HTML \\u662F\\u9884\\u751F\\u6210\\u7684\\uFF0C\\u56E0\\u6B64\\u53EF\\u4EE5\\u7ACB\\u5373\\u63D0\\u4F9B\\uFF0C\\u800C\\u65E0\\u9700\\u7B49\\u5F85\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u51CF\\u5C11\\u670D\\u52A1\\u5668\\u8D1F\\u8F7D\"}),\"\\uFF1A\\u9759\\u6001\\u6587\\u4EF6\\u53EF\\u4EE5\\u4ECE CDN \\u63D0\\u4F9B\\uFF0C\\u4ECE\\u800C\\u51CF\\u5C11\\u4E86\\u6E90\\u670D\\u52A1\\u5668\\u7684\\u8D1F\\u8F7D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u66F4\\u597D\\u7684 SEO\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u641C\\u7D22\\u5F15\\u64CE\\u7D22\\u5F15\"}),\"\\uFF1A\\u9884\\u6E32\\u67D3\\u7684 HTML \\u66F4\\u5BB9\\u6613\\u88AB\\u641C\\u7D22\\u5F15\\u64CE\\u7D22\\u5F15\\uFF0C\\u4ECE\\u800C\\u6539\\u5584 SEO\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E00\\u81F4\\u7684\\u5185\\u5BB9\"}),\"\\uFF1A\\u5185\\u5BB9\\u5728\\u8BF7\\u6C42\\u4E4B\\u95F4\\u4FDD\\u6301\\u4E00\\u81F4\\uFF0C\\u786E\\u4FDD\\u641C\\u7D22\\u5F15\\u64CE\\u770B\\u5230\\u4E0E\\u7528\\u6237\\u76F8\\u540C\\u7684\\u5185\\u5BB9\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u589E\\u5F3A\\u5B89\\u5168\\u6027\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6CA1\\u6709\\u670D\\u52A1\\u5668\\u7AEF\\u4EE3\\u7801\\u6267\\u884C\"}),\"\\uFF1A\\u7531\\u4E8E\\u6CA1\\u6709\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\uFF0C\\u670D\\u52A1\\u5668\\u7AEF\\u6F0F\\u6D1E\\u7684\\u98CE\\u9669\\u8F83\\u5C0F\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u9759\\u6001\\u6587\\u4EF6\"}),\"\\uFF1A\\u63D0\\u4F9B\\u9759\\u6001\\u6587\\u4EF6\\u51CF\\u5C11\\u4E86\\u4E0E\\u52A8\\u6001\\u5185\\u5BB9\\u751F\\u6210\\u76F8\\u6BD4\\u7684\\u653B\\u51FB\\u9762\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u53EF\\u6269\\u5C55\\u6027\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"CDN \\u5206\\u53D1\"}),\"\\uFF1A\\u9759\\u6001\\u6587\\u4EF6\\u53EF\\u4EE5\\u5728\\u591A\\u4E2A CDN \\u8282\\u70B9\\u4E4B\\u95F4\\u5206\\u53D1\\uFF0C\\u4ECE\\u800C\\u63D0\\u9AD8\\u53EF\\u6269\\u5C55\\u6027\\u5E76\\u51CF\\u5C11\\u5EF6\\u8FDF\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u9AD8\\u6548\\u7F13\\u5B58\"}),\"\\uFF1A\\u9759\\u6001\\u6587\\u4EF6\\u53EF\\u4EE5\\u8F7B\\u677E\\u7F13\\u5B58\\uFF0C\\u4ECE\\u800C\\u8FDB\\u4E00\\u6B65\\u63D0\\u9AD8\\u6027\\u80FD\\u5E76\\u51CF\\u5C11\\u670D\\u52A1\\u5668\\u8D1F\\u8F7D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Next.js \\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.p,{children:\"Next.js \\u662F\\u4E00\\u4E2A\\u6D41\\u884C\\u7684 React \\u6846\\u67B6\\uFF0C\\u652F\\u6301\\u9759\\u6001\\u751F\\u6210\\u3002\\u8FD9\\u662F\\u4E00\\u4E2A\\u5728 Next.js \\u4E2D\\u4F7F\\u7528\\u9759\\u6001\\u751F\\u6210\\u7684\\u7B80\\u5355\\u793A\\u4F8B\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`// pages/index.js\nimport React from 'react';\n\nconst HomePage = ({ data }) => {\n return (\n \n
\\u6B22\\u8FCE\\u6765\\u5230\\u6211\\u7684\\u9759\\u6001\\u7F51\\u7AD9\\uFF01 \n
{data.message}
\n
\n );\n};\n\nexport async function getStaticProps() {\n // \\u5728\\u6784\\u5EFA\\u65F6\\u83B7\\u53D6\\u6570\\u636E\n const data = { message: '\\u4F60\\u597D\\uFF0C\\u4E16\\u754C\\uFF01' };\n return {\n props: {\n data,\n },\n };\n}\n\nexport default HomePage;\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u8FD9\\u4E2A\\u4F8B\\u5B50\\u4E2D\\uFF0C\",(0,e.jsx)(n.code,{children:\"getStaticProps\"}),\" \\u51FD\\u6570\\u5728\\u6784\\u5EFA\\u65F6\\u83B7\\u53D6\\u6570\\u636E\\uFF0C\",(0,e.jsx)(n.code,{children:\"HomePage\"}),\" \\u7EC4\\u4EF6\\u4F7F\\u7528\\u8FD9\\u4E9B\\u6570\\u636E\\u6765\\u6E32\\u67D3 HTML\\u3002\"]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nextjs.org/docs/basic-features/pages#static-generation-recommended\",children:\"Next.js \\u5173\\u4E8E\\u9759\\u6001\\u751F\\u6210\\u7684\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/learn\",children:\"React \\u5B98\\u65B9\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://www.staticgen.com/\",children:\"\\u9759\\u6001\\u7AD9\\u70B9\\u751F\\u6210\\u5668\\u6BD4\\u8F83\"})}),`\n`]})]})}function N(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(a,r)})):a(r)}var L=N;return H(T);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-the-composition-pattern-in-react/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-the-composition-pattern-in-react/locales/en-US.json
index 94df0e2f6..88abc3b16 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-the-composition-pattern-in-react/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-the-composition-pattern-in-react/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain the composition pattern in React",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-the-composition-pattern-in-react/en-US.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),b=(i,n)=>{for(var o in n)s(i,o,{get:n[o],enumerable:!0})},c=(i,n,o,a)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of m(n))!g.call(i,t)&&t!==o&&s(i,t,{get:()=>n[t],enumerable:!(a=d(n,t))||a.enumerable});return i};var v=(i,n,o)=>(o=i!=null?h(u(i)):{},c(n||!i||!i.__esModule?s(o,\"default\",{value:i,enumerable:!0}):o,i)),x=i=>c(s({},\"__esModule\",{value:!0}),i);var l=f((C,r)=>{r.exports=_jsx_runtime});var R={};b(R,{default:()=>D,frontmatter:()=>y});var e=v(l()),y={title:\"Explain the composition pattern in React\"};function p(i){let n=Object.assign({h2:\"h2\",p:\"p\",pre:\"pre\",code:\"code\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"The composition pattern in React is a way to build components by combining smaller, reusable components. Instead of using inheritance, React encourages composition to create complex UIs. You can pass components as children or props to other components to achieve this. For example:\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function WelcomeDialog() {\n return (\n \n Welcome \n Thank you for visiting our spacecraft!
\n \n );\n}\n\nfunction Dialog(props) {\n return {props.children}
;\n}\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"Composition pattern in React\"}),`\n`,(0,e.jsx)(n.h3,{children:\"What is composition?\"}),`\n`,(0,e.jsx)(n.p,{children:\"Composition is a design principle that involves combining smaller, reusable components to build more complex components. In React, this is preferred over inheritance for creating complex UIs.\"}),`\n`,(0,e.jsx)(n.h3,{children:\"How to use composition in React\"}),`\n`,(0,e.jsx)(n.h4,{children:\"Passing components as children\"}),`\n`,(0,e.jsx)(n.p,{children:\"One common way to use composition is by passing components as children to other components. This allows you to nest components and create a hierarchy.\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function Dialog(props) {\n return {props.children}
;\n}\n\nfunction WelcomeDialog() {\n return (\n \n Welcome \n Thank you for visiting our spacecraft!
\n \n );\n}\n`})}),`\n`,(0,e.jsx)(n.h4,{children:\"Passing components as props\"}),`\n`,(0,e.jsx)(n.p,{children:\"Another way to achieve composition is by passing components as props. This allows for more flexibility and customization.\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function SplitPane(props) {\n return (\n \n
{props.left}
\n
{props.right}
\n
\n );\n}\n\nfunction App() {\n return } right={ } />;\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Benefits of composition\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Reusability\"}),\": Smaller components can be reused across different parts of the application.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Maintainability\"}),\": Easier to manage and update smaller components.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Flexibility\"}),\": Components can be easily combined in different ways to create complex UIs.\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"When to use composition\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"When you need to create complex UIs from smaller, reusable components.\"}),`\n`,(0,e.jsx)(n.li,{children:\"When you want to avoid the pitfalls of inheritance, such as tight coupling and difficulty in managing state.\"}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/composition-vs-inheritance.html\",children:\"React documentation on composition vs inheritance\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactpatterns.com/#composition\",children:\"React patterns: Composition\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\",children:\"Medium article on React composition\"})}),`\n`]})]})}function j(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(p,i)})):p(i)}var D=j;return x(R);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var a=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),b=(i,n)=>{for(var o in n)a(i,o,{get:n[o],enumerable:!0})},r=(i,n,o,s)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of m(n))!g.call(i,t)&&t!==o&&a(i,t,{get:()=>n[t],enumerable:!(s=d(n,t))||s.enumerable});return i};var x=(i,n,o)=>(o=i!=null?h(u(i)):{},r(n||!i||!i.__esModule?a(o,\"default\",{value:i,enumerable:!0}):o,i)),y=i=>r(a({},\"__esModule\",{value:!0}),i);var l=f((C,c)=>{c.exports=_jsx_runtime});var R={};b(R,{default:()=>j,frontmatter:()=>v});var e=x(l()),v={title:\"Explain the composition pattern in React\"};function p(i){let n=Object.assign({h2:\"h2\",p:\"p\",pre:\"pre\",code:\"code\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"The composition pattern in React is a way to build components by combining smaller, reusable components. Instead of using inheritance, React encourages composition to create complex UIs. You can pass components as children or props to other components to achieve this. For example:\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function WelcomeDialog() {\n return (\n \n Welcome \n Thank you for visiting our spacecraft!
\n \n );\n}\n\nfunction Dialog(props) {\n return {props.children}
;\n}\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"Composition pattern in React\"}),`\n`,(0,e.jsx)(n.h3,{children:\"What is composition?\"}),`\n`,(0,e.jsx)(n.p,{children:\"Composition is a design principle that involves combining smaller, reusable components to build more complex components. In React, this is preferred over inheritance for creating complex UIs.\"}),`\n`,(0,e.jsx)(n.h3,{children:\"How to use composition in React\"}),`\n`,(0,e.jsx)(n.h4,{children:\"Passing components as children\"}),`\n`,(0,e.jsx)(n.p,{children:\"One common way to use composition is by passing components as children to other components. This allows you to nest components and create a hierarchy.\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function Dialog(props) {\n return {props.children}
;\n}\n\nfunction WelcomeDialog() {\n return (\n \n Welcome \n Thank you for visiting our spacecraft!
\n \n );\n}\n`})}),`\n`,(0,e.jsx)(n.h4,{children:\"Passing components as props\"}),`\n`,(0,e.jsx)(n.p,{children:\"Another way to achieve composition is by passing components as props. This allows for more flexibility and customization.\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function SplitPane(props) {\n return (\n \n
{props.left}
\n
{props.right}
\n
\n );\n}\n\nfunction App() {\n return } right={ } />;\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Benefits of composition\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Reusability\"}),\": Smaller components can be reused across different parts of the application.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Maintainability\"}),\": Easier to manage and update smaller components.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Flexibility\"}),\": Components can be easily combined in different ways to create complex UIs.\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"When to use composition\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"When you need to create complex UIs from smaller, reusable components.\"}),`\n`,(0,e.jsx)(n.li,{children:\"When you want to avoid the pitfalls of inheritance, such as tight coupling and difficulty in managing state.\"}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://krasimir.gitbooks.io/react-in-patterns/content/chapter-04/\",children:\"Composition in React\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\",children:\"Medium article on React composition\"})}),`\n`]})]})}function D(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(p,i)})):p(i)}var j=D;return y(R);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-the-composition-pattern-in-react/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-the-composition-pattern-in-react/locales/zh-CN.json
index eabd9b60e..d89577d2e 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-the-composition-pattern-in-react/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-the-composition-pattern-in-react/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释 React 中的组合模式",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-the-composition-pattern-in-react/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var d=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),v=(r,n)=>{for(var i in n)l(r,i,{get:n[i],enumerable:!0})},a=(r,n,i,t)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of u(n))!g.call(r,c)&&c!==i&&l(r,c,{get:()=>n[c],enumerable:!(t=p(n,c))||t.enumerable});return r};var x=(r,n,i)=>(i=r!=null?d(m(r)):{},a(n||!r||!r.__esModule?l(i,\"default\",{value:r,enumerable:!0}):i,r)),j=r=>a(l({},\"__esModule\",{value:!0}),r);var h=f((C,o)=>{o.exports=_jsx_runtime});var _={};v(_,{default:()=>N,frontmatter:()=>D});var e=x(h()),D={title:\"\\u89E3\\u91CA React \\u4E2D\\u7684\\u7EC4\\u5408\\u6A21\\u5F0F\"};function s(r){let n=Object.assign({h2:\"h2\",p:\"p\",pre:\"pre\",code:\"code\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u4E2D\\u7684\\u7EC4\\u5408\\u6A21\\u5F0F\\u662F\\u4E00\\u79CD\\u901A\\u8FC7\\u7EC4\\u5408\\u66F4\\u5C0F\\u3001\\u53EF\\u590D\\u7528\\u7684\\u7EC4\\u4EF6\\u6765\\u6784\\u5EFA\\u7EC4\\u4EF6\\u7684\\u65B9\\u5F0F\\u3002React \\u9F13\\u52B1\\u4F7F\\u7528\\u7EC4\\u5408\\u6765\\u521B\\u5EFA\\u590D\\u6742\\u7684 UI\\uFF0C\\u800C\\u4E0D\\u662F\\u4F7F\\u7528\\u7EE7\\u627F\\u3002\\u4F60\\u53EF\\u4EE5\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A\\u5B50\\u7EC4\\u4EF6\\u6216 props \\u4F20\\u9012\\u7ED9\\u5176\\u4ED6\\u7EC4\\u4EF6\\u6765\\u5B9E\\u73B0\\u8FD9\\u4E00\\u70B9\\u3002\\u4F8B\\u5982\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function WelcomeDialog() {\n return (\n \n Welcome \n Thank you for visiting our spacecraft!
\n \n );\n}\n\nfunction Dialog(props) {\n return {props.children}
;\n}\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"React \\u4E2D\\u7684\\u7EC4\\u5408\\u6A21\\u5F0F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EC0\\u4E48\\u662F\\u7EC4\\u5408\\uFF1F\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7EC4\\u5408\\u662F\\u4E00\\u79CD\\u8BBE\\u8BA1\\u539F\\u5219\\uFF0C\\u5B83\\u6D89\\u53CA\\u7EC4\\u5408\\u66F4\\u5C0F\\u3001\\u53EF\\u590D\\u7528\\u7684\\u7EC4\\u4EF6\\u6765\\u6784\\u5EFA\\u66F4\\u590D\\u6742\\u7684\\u7EC4\\u4EF6\\u3002\\u5728 React \\u4E2D\\uFF0C\\u8FD9\\u6BD4\\u7EE7\\u627F\\u66F4\\u9002\\u5408\\u521B\\u5EFA\\u590D\\u6742\\u7684 UI\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5982\\u4F55\\u5728 React \\u4E2D\\u4F7F\\u7528\\u7EC4\\u5408\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A\\u5B50\\u7EC4\\u4EF6\\u4F20\\u9012\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4F7F\\u7528\\u7EC4\\u5408\\u7684\\u4E00\\u79CD\\u5E38\\u89C1\\u65B9\\u6CD5\\u662F\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A\\u5B50\\u7EC4\\u4EF6\\u4F20\\u9012\\u7ED9\\u5176\\u4ED6\\u7EC4\\u4EF6\\u3002\\u8FD9\\u5141\\u8BB8\\u4F60\\u5D4C\\u5957\\u7EC4\\u4EF6\\u5E76\\u521B\\u5EFA\\u4E00\\u4E2A\\u5C42\\u6B21\\u7ED3\\u6784\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function Dialog(props) {\n return {props.children}
;\n}\n\nfunction WelcomeDialog() {\n return (\n \n Welcome \n Thank you for visiting our spacecraft!
\n \n );\n}\n`})}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A props \\u4F20\\u9012\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5B9E\\u73B0\\u7EC4\\u5408\\u7684\\u53E6\\u4E00\\u79CD\\u65B9\\u6CD5\\u662F\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A props \\u4F20\\u9012\\u3002\\u8FD9\\u5141\\u8BB8\\u66F4\\u5927\\u7684\\u7075\\u6D3B\\u6027\\u548C\\u81EA\\u5B9A\\u4E49\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function SplitPane(props) {\n return (\n \n
{props.left}
\n
{props.right}
\n
\n );\n}\n\nfunction App() {\n return } right={ } />;\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EC4\\u5408\\u7684\\u4F18\\u70B9\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53EF\\u91CD\\u7528\\u6027\"}),\"\\uFF1A\\u8F83\\u5C0F\\u7684\\u7EC4\\u4EF6\\u53EF\\u4EE5\\u5728\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u4E0D\\u540C\\u90E8\\u5206\\u91CD\\u590D\\u4F7F\\u7528\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53EF\\u7EF4\\u62A4\\u6027\"}),\"\\uFF1A\\u66F4\\u5BB9\\u6613\\u7BA1\\u7406\\u548C\\u66F4\\u65B0\\u8F83\\u5C0F\\u7684\\u7EC4\\u4EF6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7075\\u6D3B\\u6027\"}),\"\\uFF1A\\u7EC4\\u4EF6\\u53EF\\u4EE5\\u4EE5\\u4E0D\\u540C\\u7684\\u65B9\\u5F0F\\u8F7B\\u677E\\u7EC4\\u5408\\uFF0C\\u4EE5\\u521B\\u5EFA\\u590D\\u6742\\u7684 UI\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EC0\\u4E48\\u65F6\\u5019\\u4F7F\\u7528\\u7EC4\\u5408\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u4F60\\u9700\\u8981\\u4ECE\\u66F4\\u5C0F\\u3001\\u53EF\\u91CD\\u7528\\u7684\\u7EC4\\u4EF6\\u521B\\u5EFA\\u590D\\u6742\\u7684 UI \\u65F6\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u4F60\\u60F3\\u907F\\u514D\\u7EE7\\u627F\\u7684\\u7F3A\\u9677\\u65F6\\uFF0C\\u4F8B\\u5982\\u7D27\\u5BC6\\u8026\\u5408\\u548C\\u96BE\\u4EE5\\u7BA1\\u7406\\u72B6\\u6001\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/composition-vs-inheritance.html\",children:\"React \\u5173\\u4E8E\\u7EC4\\u5408\\u800C\\u975E\\u7EE7\\u627F\\u7684\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactpatterns.com/#composition\",children:\"React \\u6A21\\u5F0F\\uFF1A\\u7EC4\\u5408\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\",children:\"\\u5173\\u4E8E React \\u7EC4\\u5408\\u7684 Medium \\u6587\\u7AE0\"})}),`\n`]})]})}function R(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(s,r)})):s(r)}var N=R;return j(_);})();\n;return Component;"
+ "solution": "var Component=(()=>{var d=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var f=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),v=(r,n)=>{for(var i in n)l(r,i,{get:n[i],enumerable:!0})},a=(r,n,i,t)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of u(n))!m.call(r,c)&&c!==i&&l(r,c,{get:()=>n[c],enumerable:!(t=p(n,c))||t.enumerable});return r};var x=(r,n,i)=>(i=r!=null?d(g(r)):{},a(n||!r||!r.__esModule?l(i,\"default\",{value:r,enumerable:!0}):i,r)),D=r=>a(l({},\"__esModule\",{value:!0}),r);var h=f((k,o)=>{o.exports=_jsx_runtime});var _={};v(_,{default:()=>N,frontmatter:()=>j});var e=x(h()),j={title:\"\\u89E3\\u91CA React \\u4E2D\\u7684\\u7EC4\\u5408\\u6A21\\u5F0F\"};function s(r){let n=Object.assign({h2:\"h2\",p:\"p\",pre:\"pre\",code:\"code\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u4E2D\\u7684\\u7EC4\\u5408\\u6A21\\u5F0F\\u662F\\u4E00\\u79CD\\u901A\\u8FC7\\u7EC4\\u5408\\u66F4\\u5C0F\\u3001\\u53EF\\u590D\\u7528\\u7684\\u7EC4\\u4EF6\\u6765\\u6784\\u5EFA\\u7EC4\\u4EF6\\u7684\\u65B9\\u5F0F\\u3002React \\u9F13\\u52B1\\u4F7F\\u7528\\u7EC4\\u5408\\u6765\\u521B\\u5EFA\\u590D\\u6742\\u7684 UI\\uFF0C\\u800C\\u4E0D\\u662F\\u4F7F\\u7528\\u7EE7\\u627F\\u3002\\u4F60\\u53EF\\u4EE5\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A\\u5B50\\u7EC4\\u4EF6\\u6216 props \\u4F20\\u9012\\u7ED9\\u5176\\u4ED6\\u7EC4\\u4EF6\\u6765\\u5B9E\\u73B0\\u8FD9\\u4E00\\u70B9\\u3002\\u4F8B\\u5982\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function WelcomeDialog() {\n return (\n \n Welcome \n Thank you for visiting our spacecraft!
\n \n );\n}\n\nfunction Dialog(props) {\n return {props.children}
;\n}\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"React \\u4E2D\\u7684\\u7EC4\\u5408\\u6A21\\u5F0F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EC0\\u4E48\\u662F\\u7EC4\\u5408\\uFF1F\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7EC4\\u5408\\u662F\\u4E00\\u79CD\\u8BBE\\u8BA1\\u539F\\u5219\\uFF0C\\u5B83\\u6D89\\u53CA\\u7EC4\\u5408\\u66F4\\u5C0F\\u3001\\u53EF\\u590D\\u7528\\u7684\\u7EC4\\u4EF6\\u6765\\u6784\\u5EFA\\u66F4\\u590D\\u6742\\u7684\\u7EC4\\u4EF6\\u3002\\u5728 React \\u4E2D\\uFF0C\\u8FD9\\u6BD4\\u7EE7\\u627F\\u66F4\\u9002\\u5408\\u521B\\u5EFA\\u590D\\u6742\\u7684 UI\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5982\\u4F55\\u5728 React \\u4E2D\\u4F7F\\u7528\\u7EC4\\u5408\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A\\u5B50\\u7EC4\\u4EF6\\u4F20\\u9012\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4F7F\\u7528\\u7EC4\\u5408\\u7684\\u4E00\\u79CD\\u5E38\\u89C1\\u65B9\\u6CD5\\u662F\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A\\u5B50\\u7EC4\\u4EF6\\u4F20\\u9012\\u7ED9\\u5176\\u4ED6\\u7EC4\\u4EF6\\u3002\\u8FD9\\u5141\\u8BB8\\u4F60\\u5D4C\\u5957\\u7EC4\\u4EF6\\u5E76\\u521B\\u5EFA\\u4E00\\u4E2A\\u5C42\\u6B21\\u7ED3\\u6784\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function Dialog(props) {\n return {props.children}
;\n}\n\nfunction WelcomeDialog() {\n return (\n \n Welcome \n Thank you for visiting our spacecraft!
\n \n );\n}\n`})}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A props \\u4F20\\u9012\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5B9E\\u73B0\\u7EC4\\u5408\\u7684\\u53E6\\u4E00\\u79CD\\u65B9\\u6CD5\\u662F\\u5C06\\u7EC4\\u4EF6\\u4F5C\\u4E3A props \\u4F20\\u9012\\u3002\\u8FD9\\u5141\\u8BB8\\u66F4\\u5927\\u7684\\u7075\\u6D3B\\u6027\\u548C\\u81EA\\u5B9A\\u4E49\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`function SplitPane(props) {\n return (\n \n
{props.left}
\n
{props.right}
\n
\n );\n}\n\nfunction App() {\n return } right={ } />;\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7EC4\\u5408\\u7684\\u4F18\\u70B9\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53EF\\u91CD\\u7528\\u6027\"}),\"\\uFF1A\\u8F83\\u5C0F\\u7684\\u7EC4\\u4EF6\\u53EF\\u4EE5\\u5728\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u4E0D\\u540C\\u90E8\\u5206\\u91CD\\u590D\\u4F7F\\u7528\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53EF\\u7EF4\\u62A4\\u6027\"}),\"\\uFF1A\\u66F4\\u5BB9\\u6613\\u7BA1\\u7406\\u548C\\u66F4\\u65B0\\u8F83\\u5C0F\\u7684\\u7EC4\\u4EF6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7075\\u6D3B\\u6027\"}),\"\\uFF1A\\u7EC4\\u4EF6\\u53EF\\u4EE5\\u4EE5\\u4E0D\\u540C\\u7684\\u65B9\\u5F0F\\u8F7B\\u677E\\u7EC4\\u5408\\uFF0C\\u4EE5\\u521B\\u5EFA\\u590D\\u6742\\u7684 UI\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4EC0\\u4E48\\u65F6\\u5019\\u4F7F\\u7528\\u7EC4\\u5408\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u4F60\\u9700\\u8981\\u4ECE\\u66F4\\u5C0F\\u3001\\u53EF\\u91CD\\u7528\\u7684\\u7EC4\\u4EF6\\u521B\\u5EFA\\u590D\\u6742\\u7684 UI \\u65F6\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u4F60\\u60F3\\u907F\\u514D\\u7EE7\\u627F\\u7684\\u7F3A\\u9677\\u65F6\\uFF0C\\u4F8B\\u5982\\u7D27\\u5BC6\\u8026\\u5408\\u548C\\u96BE\\u4EE5\\u7BA1\\u7406\\u72B6\\u6001\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://krasimir.gitbooks.io/react-in-patterns/content/chapter-04/\",children:\"React \\u4E2D\\u7684\\u7EC4\\u5408\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\",children:\"\\u5173\\u4E8E React \\u7EC4\\u5408\\u7684 Medium \\u6587\\u7AE0\"})}),`\n`]})]})}function R(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(s,r)})):s(r)}var N=R;return D(_);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-the-concept-of-a-callback-function-in-asynchronous-operations/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-the-concept-of-a-callback-function-in-asynchronous-operations/locales/en-US.json
index ba5f6550b..e93a7f00a 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-the-concept-of-a-callback-function-in-asynchronous-operations/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-the-concept-of-a-callback-function-in-asynchronous-operations/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain the concept of a callback function in asynchronous operations",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/explain-the-concept-of-a-callback-function-in-asynchronous-operations/en-US.mdx"
},
- "solution": "var Component=(()=>{var d=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var p=(a,n)=>()=>(n||a((n={exports:{}}).exports,n),n.exports),k=(a,n)=>{for(var o in n)c(a,o,{get:n[o],enumerable:!0})},l=(a,n,o,r)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of g(n))!m.call(a,t)&&t!==o&&c(a,t,{get:()=>n[t],enumerable:!(r=u(n,t))||r.enumerable});return a};var b=(a,n,o)=>(o=a!=null?d(f(a)):{},l(n||!a||!a.__esModule?c(o,\"default\",{value:a,enumerable:!0}):o,a)),y=a=>l(c({},\"__esModule\",{value:!0}),a);var s=p((A,i)=>{i.exports=_jsx_runtime});var v={};k(v,{default:()=>j,frontmatter:()=>x});var e=b(s()),x={title:\"Explain the concept of a callback function in asynchronous operations\"};function h(a){let n=Object.assign({h2:\"h2\",p:\"p\",pre:\"pre\",code:\"code\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},a.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"A callback function is a function passed as an argument to another function, which is then invoked inside the outer function to complete some kind of routine or action. In asynchronous operations, callbacks are used to handle tasks that take time to complete, such as network requests or file I/O, without blocking the execution of the rest of the code. For example:\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n setTimeout(() => {\n const data = { name: 'John', age: 30 };\n callback(data);\n }, 1000);\n}\n\nfetchData((data) => {\n console.log(data);\n});\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"What is a callback function?\"}),`\n`,(0,e.jsx)(n.p,{children:\"A callback function is a function that is passed as an argument to another function and is executed after some operation has been completed. This is particularly useful in asynchronous programming, where operations like network requests, file I/O, or timers need to be handled without blocking the main execution thread.\"}),`\n`,(0,e.jsx)(n.h3,{children:\"Synchronous vs. asynchronous callbacks\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Synchronous callbacks\"}),\" are executed immediately within the function they are passed to. They are blocking and the code execution waits for them to complete.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Asynchronous callbacks\"}),\" are executed after a certain event or operation has been completed. They are non-blocking and allow the code execution to continue while waiting for the operation to finish.\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Example of a synchronous callback\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function greet(name, callback) {\n console.log('Hello ' + name);\n callback();\n}\n\nfunction sayGoodbye() {\n console.log('Goodbye!');\n}\n\ngreet('Alice', sayGoodbye);\n// Output:\n// Hello Alice\n// Goodbye!\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Example of an asynchronous callback\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n setTimeout(() => {\n const data = { name: 'John', age: 30 };\n callback(data);\n }, 1000);\n}\n\nfetchData((data) => {\n console.log(data);\n});\n// Output after 1 second:\n// { name: 'John', age: 30 }\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Common use cases\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Network requests\"}),\": Fetching data from an API\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"File I/O\"}),\": Reading or writing files\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Timers\"}),\": Delaying execution using \",(0,e.jsx)(n.code,{children:\"setTimeout\"}),\" or \",(0,e.jsx)(n.code,{children:\"setInterval\"})]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Event handling\"}),\": Responding to user actions like clicks or key presses\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Handling errors in callbacks\"}),`\n`,(0,e.jsx)(n.p,{children:\"When dealing with asynchronous operations, it's important to handle errors properly. A common pattern is to use the first argument of the callback function to pass an error object, if any.\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n // assume asynchronous operation to fetch data\n const { data, error } = { data: { name: 'John', age: 30 }, error: null };\n callback(error, data);\n}\n\nfetchData((error, data) => {\n if (error) {\n console.error('An error occurred:', error);\n } else {\n console.log(data);\n }\n});\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Glossary/Callback_function\",children:\"MDN Web Docs: Callback function\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/callbacks\",children:\"JavaScript.info: Callbacks\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nodejs.org/en/knowledge/getting-started/control-flow/what-are-callbacks/\",children:\"Node.js: Asynchronous programming and callbacks\"})}),`\n`]})]})}function w(a={}){let{wrapper:n}=a.components||{};return n?(0,e.jsx)(n,Object.assign({},a,{children:(0,e.jsx)(h,a)})):h(a)}var j=w;return y(v);})();\n;return Component;"
+ "solution": "var Component=(()=>{var d=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var p=(a,n)=>()=>(n||a((n={exports:{}}).exports,n),n.exports),k=(a,n)=>{for(var o in n)c(a,o,{get:n[o],enumerable:!0})},l=(a,n,o,r)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of g(n))!m.call(a,t)&&t!==o&&c(a,t,{get:()=>n[t],enumerable:!(r=u(n,t))||r.enumerable});return a};var b=(a,n,o)=>(o=a!=null?d(f(a)):{},l(n||!a||!a.__esModule?c(o,\"default\",{value:a,enumerable:!0}):o,a)),y=a=>l(c({},\"__esModule\",{value:!0}),a);var s=p((A,i)=>{i.exports=_jsx_runtime});var v={};k(v,{default:()=>w,frontmatter:()=>x});var e=b(s()),x={title:\"Explain the concept of a callback function in asynchronous operations\"};function h(a){let n=Object.assign({h2:\"h2\",p:\"p\",pre:\"pre\",code:\"code\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},a.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"A callback function is a function passed as an argument to another function, which is then invoked inside the outer function to complete some kind of routine or action. In asynchronous operations, callbacks are used to handle tasks that take time to complete, such as network requests or file I/O, without blocking the execution of the rest of the code. For example:\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n setTimeout(() => {\n const data = { name: 'John', age: 30 };\n callback(data);\n }, 1000);\n}\n\nfetchData((data) => {\n console.log(data);\n});\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"What is a callback function?\"}),`\n`,(0,e.jsx)(n.p,{children:\"A callback function is a function that is passed as an argument to another function and is executed after some operation has been completed. This is particularly useful in asynchronous programming, where operations like network requests, file I/O, or timers need to be handled without blocking the main execution thread.\"}),`\n`,(0,e.jsx)(n.h3,{children:\"Synchronous vs. asynchronous callbacks\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Synchronous callbacks\"}),\" are executed immediately within the function they are passed to. They are blocking and the code execution waits for them to complete.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Asynchronous callbacks\"}),\" are executed after a certain event or operation has been completed. They are non-blocking and allow the code execution to continue while waiting for the operation to finish.\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Example of a synchronous callback\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function greet(name, callback) {\n console.log('Hello ' + name);\n callback();\n}\n\nfunction sayGoodbye() {\n console.log('Goodbye!');\n}\n\ngreet('Alice', sayGoodbye);\n// Output:\n// Hello Alice\n// Goodbye!\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Example of an asynchronous callback\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n setTimeout(() => {\n const data = { name: 'John', age: 30 };\n callback(data);\n }, 1000);\n}\n\nfetchData((data) => {\n console.log(data);\n});\n// Output after 1 second:\n// { name: 'John', age: 30 }\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Common use cases\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Network requests\"}),\": Fetching data from an API\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"File I/O\"}),\": Reading or writing files\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Timers\"}),\": Delaying execution using \",(0,e.jsx)(n.code,{children:\"setTimeout\"}),\" or \",(0,e.jsx)(n.code,{children:\"setInterval\"})]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Event handling\"}),\": Responding to user actions like clicks or key presses\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Handling errors in callbacks\"}),`\n`,(0,e.jsx)(n.p,{children:\"When dealing with asynchronous operations, it's important to handle errors properly. A common pattern is to use the first argument of the callback function to pass an error object, if any.\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n // assume asynchronous operation to fetch data\n const { data, error } = { data: { name: 'John', age: 30 }, error: null };\n callback(error, data);\n}\n\nfetchData((error, data) => {\n if (error) {\n console.error('An error occurred:', error);\n } else {\n console.log(data);\n }\n});\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Glossary/Callback_function\",children:\"MDN Web Docs: Callback function\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/callbacks\",children:\"JavaScript.info: Callbacks\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nodejs.org/en/learn/asynchronous-work/javascript-asynchronous-programming-and-callbacks\",children:\"Node.js: Asynchronous programming and callbacks\"})}),`\n`]})]})}function j(a={}){let{wrapper:n}=a.components||{};return n?(0,e.jsx)(n,Object.assign({},a,{children:(0,e.jsx)(h,a)})):h(a)}var w=j;return y(v);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-the-concept-of-a-callback-function-in-asynchronous-operations/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-the-concept-of-a-callback-function-in-asynchronous-operations/locales/zh-CN.json
index 426364394..e333b5afc 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-the-concept-of-a-callback-function-in-asynchronous-operations/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-the-concept-of-a-callback-function-in-asynchronous-operations/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释异步操作中回调函数的概念",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/explain-the-concept-of-a-callback-function-in-asynchronous-operations/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var r=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var p=(l,n)=>()=>(n||l((n={exports:{}}).exports,n),n.exports),b=(l,n)=>{for(var a in n)r(l,a,{get:n[a],enumerable:!0})},o=(l,n,a,t)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of g(n))!m.call(l,c)&&c!==a&&r(l,c,{get:()=>n[c],enumerable:!(t=u(n,c))||t.enumerable});return l};var k=(l,n,a)=>(a=l!=null?s(f(l)):{},o(n||!l||!l.__esModule?r(a,\"default\",{value:l,enumerable:!0}):a,l)),j=l=>o(r({},\"__esModule\",{value:!0}),l);var d=p((O,i)=>{i.exports=_jsx_runtime});var v={};b(v,{default:()=>x,frontmatter:()=>D});var e=k(d()),D={title:\"\\u89E3\\u91CA\\u5F02\\u6B65\\u64CD\\u4F5C\\u4E2D\\u56DE\\u8C03\\u51FD\\u6570\\u7684\\u6982\\u5FF5\"};function h(l){let n=Object.assign({h2:\"h2\",p:\"p\",pre:\"pre\",code:\"code\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},l.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u56DE\\u8C03\\u51FD\\u6570\\u662F\\u4F5C\\u4E3A\\u53C2\\u6570\\u4F20\\u9012\\u7ED9\\u53E6\\u4E00\\u4E2A\\u51FD\\u6570\\u7684\\u51FD\\u6570\\uFF0C\\u7136\\u540E\\u5728\\u5916\\u90E8\\u51FD\\u6570\\u4E2D\\u8C03\\u7528\\u8BE5\\u51FD\\u6570\\u4EE5\\u5B8C\\u6210\\u67D0\\u79CD\\u4F8B\\u7A0B\\u6216\\u64CD\\u4F5C\\u3002\\u5728\\u5F02\\u6B65\\u64CD\\u4F5C\\u4E2D\\uFF0C\\u56DE\\u8C03\\u7528\\u4E8E\\u5904\\u7406\\u9700\\u8981\\u65F6\\u95F4\\u624D\\u80FD\\u5B8C\\u6210\\u7684\\u4EFB\\u52A1\\uFF0C\\u4F8B\\u5982\\u7F51\\u7EDC\\u8BF7\\u6C42\\u6216\\u6587\\u4EF6 I/O\\uFF0C\\u800C\\u4E0D\\u4F1A\\u963B\\u585E\\u5176\\u4F59\\u4EE3\\u7801\\u7684\\u6267\\u884C\\u3002\\u4F8B\\u5982\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n setTimeout(() => {\n const data = { name: 'John', age: 30 };\n callback(data);\n }, 1000);\n}\n\nfetchData((data) => {\n console.log(data);\n});\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4EC0\\u4E48\\u662F\\u56DE\\u8C03\\u51FD\\u6570\\uFF1F\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u56DE\\u8C03\\u51FD\\u6570\\u662F\\u4F5C\\u4E3A\\u53C2\\u6570\\u4F20\\u9012\\u7ED9\\u53E6\\u4E00\\u4E2A\\u51FD\\u6570\\u5E76\\u5728\\u5B8C\\u6210\\u67D0\\u4E9B\\u64CD\\u4F5C\\u540E\\u6267\\u884C\\u7684\\u51FD\\u6570\\u3002\\u8FD9\\u5728\\u5F02\\u6B65\\u7F16\\u7A0B\\u4E2D\\u7279\\u522B\\u6709\\u7528\\uFF0C\\u5176\\u4E2D\\u9700\\u8981\\u5904\\u7406\\u7F51\\u7EDC\\u8BF7\\u6C42\\u3001\\u6587\\u4EF6 I/O \\u6216\\u8BA1\\u65F6\\u5668\\u7B49\\u64CD\\u4F5C\\uFF0C\\u800C\\u4E0D\\u4F1A\\u963B\\u585E\\u4E3B\\u6267\\u884C\\u7EBF\\u7A0B\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u540C\\u6B65\\u4E0E\\u5F02\\u6B65\\u56DE\\u8C03\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u540C\\u6B65\\u56DE\\u8C03\"}),\" \\u5728\\u4F20\\u9012\\u7ED9\\u5B83\\u4EEC\\u7684\\u51FD\\u6570\\u4E2D\\u7ACB\\u5373\\u6267\\u884C\\u3002\\u5B83\\u4EEC\\u662F\\u963B\\u585E\\u7684\\uFF0C\\u4EE3\\u7801\\u6267\\u884C\\u4F1A\\u7B49\\u5F85\\u5B83\\u4EEC\\u5B8C\\u6210\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5F02\\u6B65\\u56DE\\u8C03\"}),\" \\u5728\\u5B8C\\u6210\\u67D0\\u4E2A\\u4E8B\\u4EF6\\u6216\\u64CD\\u4F5C\\u540E\\u6267\\u884C\\u3002\\u5B83\\u4EEC\\u662F\\u975E\\u963B\\u585E\\u7684\\uFF0C\\u5141\\u8BB8\\u4EE3\\u7801\\u6267\\u884C\\u5728\\u7B49\\u5F85\\u64CD\\u4F5C\\u5B8C\\u6210\\u7684\\u540C\\u65F6\\u7EE7\\u7EED\\u8FDB\\u884C\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u540C\\u6B65\\u56DE\\u8C03\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function greet(name, callback) {\n console.log('Hello ' + name);\n callback();\n}\n\nfunction sayGoodbye() {\n console.log('Goodbye!');\n}\n\ngreet('Alice', sayGoodbye);\n// Output:\n// Hello Alice\n// Goodbye!\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5F02\\u6B65\\u56DE\\u8C03\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n setTimeout(() => {\n const data = { name: 'John', age: 30 };\n callback(data);\n }, 1000);\n}\n\nfetchData((data) => {\n console.log(data);\n});\n// Output after 1 second:\n// { name: 'John', age: 30 }\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5E38\\u89C1\\u7528\\u4F8B\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7F51\\u7EDC\\u8BF7\\u6C42\"}),\"\\uFF1A\\u4ECE API \\u83B7\\u53D6\\u6570\\u636E\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6587\\u4EF6 I/O\"}),\"\\uFF1A\\u8BFB\\u53D6\\u6216\\u5199\\u5165\\u6587\\u4EF6\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u8BA1\\u65F6\\u5668\"}),\"\\uFF1A\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"setTimeout\"}),\" \\u6216 \",(0,e.jsx)(n.code,{children:\"setInterval\"}),\" \\u5EF6\\u8FDF\\u6267\\u884C\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E8B\\u4EF6\\u5904\\u7406\"}),\"\\uFF1A\\u54CD\\u5E94\\u7528\\u6237\\u64CD\\u4F5C\\uFF0C\\u5982\\u5355\\u51FB\\u6216\\u6309\\u952E\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5728\\u56DE\\u8C03\\u4E2D\\u5904\\u7406\\u9519\\u8BEF\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5904\\u7406\\u5F02\\u6B65\\u64CD\\u4F5C\\u65F6\\uFF0C\\u6B63\\u786E\\u5904\\u7406\\u9519\\u8BEF\\u975E\\u5E38\\u91CD\\u8981\\u3002\\u4E00\\u4E2A\\u5E38\\u89C1\\u7684\\u6A21\\u5F0F\\u662F\\u4F7F\\u7528\\u56DE\\u8C03\\u51FD\\u6570\\u7684\\u7B2C\\u4E00\\u4E2A\\u53C2\\u6570\\u6765\\u4F20\\u9012\\u4E00\\u4E2A\\u9519\\u8BEF\\u5BF9\\u8C61\\uFF08\\u5982\\u679C\\u6709\\uFF09\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n // assume asynchronous operation to fetch data\n const { data, error } = { data: { name: 'John', age: 30 }, error: null };\n callback(error, data);\n}\n\nfetchData((error, data) => {\n if (error) {\n console.error('An error occurred:', error);\n } else {\n console.log(data);\n }\n});\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Glossary/Callback_function\",children:\"MDN Web Docs: Callback function\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/callbacks\",children:\"JavaScript.info: Callbacks\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nodejs.org/en/knowledge/getting-started/control-flow/what-are-callbacks/\",children:\"Node.js: Asynchronous programming and callbacks\"})}),`\n`]})]})}function y(l={}){let{wrapper:n}=l.components||{};return n?(0,e.jsx)(n,Object.assign({},l,{children:(0,e.jsx)(h,l)})):h(l)}var x=y;return j(v);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var p=(a,n)=>()=>(n||a((n={exports:{}}).exports,n),n.exports),b=(a,n)=>{for(var r in n)l(a,r,{get:n[r],enumerable:!0})},t=(a,n,r,o)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of g(n))!f.call(a,c)&&c!==r&&l(a,c,{get:()=>n[c],enumerable:!(o=u(n,c))||o.enumerable});return a};var j=(a,n,r)=>(r=a!=null?s(m(a)):{},t(n||!a||!a.__esModule?l(r,\"default\",{value:a,enumerable:!0}):r,a)),k=a=>t(l({},\"__esModule\",{value:!0}),a);var d=p((O,i)=>{i.exports=_jsx_runtime});var x={};b(x,{default:()=>v,frontmatter:()=>y});var e=j(d()),y={title:\"\\u89E3\\u91CA\\u5F02\\u6B65\\u64CD\\u4F5C\\u4E2D\\u56DE\\u8C03\\u51FD\\u6570\\u7684\\u6982\\u5FF5\"};function h(a){let n=Object.assign({h2:\"h2\",p:\"p\",pre:\"pre\",code:\"code\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},a.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u56DE\\u8C03\\u51FD\\u6570\\u662F\\u4F5C\\u4E3A\\u53C2\\u6570\\u4F20\\u9012\\u7ED9\\u53E6\\u4E00\\u4E2A\\u51FD\\u6570\\u7684\\u51FD\\u6570\\uFF0C\\u7136\\u540E\\u5728\\u5916\\u90E8\\u51FD\\u6570\\u4E2D\\u8C03\\u7528\\u8BE5\\u51FD\\u6570\\u4EE5\\u5B8C\\u6210\\u67D0\\u79CD\\u4F8B\\u7A0B\\u6216\\u64CD\\u4F5C\\u3002\\u5728\\u5F02\\u6B65\\u64CD\\u4F5C\\u4E2D\\uFF0C\\u56DE\\u8C03\\u7528\\u4E8E\\u5904\\u7406\\u9700\\u8981\\u65F6\\u95F4\\u624D\\u80FD\\u5B8C\\u6210\\u7684\\u4EFB\\u52A1\\uFF0C\\u4F8B\\u5982\\u7F51\\u7EDC\\u8BF7\\u6C42\\u6216\\u6587\\u4EF6 I/O\\uFF0C\\u800C\\u4E0D\\u4F1A\\u963B\\u585E\\u5176\\u4F59\\u4EE3\\u7801\\u7684\\u6267\\u884C\\u3002\\u4F8B\\u5982\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n setTimeout(() => {\n const data = { name: 'John', age: 30 };\n callback(data);\n }, 1000);\n}\n\nfetchData((data) => {\n console.log(data);\n});\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4EC0\\u4E48\\u662F\\u56DE\\u8C03\\u51FD\\u6570\\uFF1F\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u56DE\\u8C03\\u51FD\\u6570\\u662F\\u4F5C\\u4E3A\\u53C2\\u6570\\u4F20\\u9012\\u7ED9\\u53E6\\u4E00\\u4E2A\\u51FD\\u6570\\u5E76\\u5728\\u5B8C\\u6210\\u67D0\\u4E9B\\u64CD\\u4F5C\\u540E\\u6267\\u884C\\u7684\\u51FD\\u6570\\u3002\\u8FD9\\u5728\\u5F02\\u6B65\\u7F16\\u7A0B\\u4E2D\\u7279\\u522B\\u6709\\u7528\\uFF0C\\u5176\\u4E2D\\u9700\\u8981\\u5904\\u7406\\u7F51\\u7EDC\\u8BF7\\u6C42\\u3001\\u6587\\u4EF6 I/O \\u6216\\u8BA1\\u65F6\\u5668\\u7B49\\u64CD\\u4F5C\\uFF0C\\u800C\\u4E0D\\u4F1A\\u963B\\u585E\\u4E3B\\u6267\\u884C\\u7EBF\\u7A0B\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u540C\\u6B65\\u4E0E\\u5F02\\u6B65\\u56DE\\u8C03\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u540C\\u6B65\\u56DE\\u8C03\"}),\" \\u5728\\u4F20\\u9012\\u7ED9\\u5B83\\u4EEC\\u7684\\u51FD\\u6570\\u4E2D\\u7ACB\\u5373\\u6267\\u884C\\u3002\\u5B83\\u4EEC\\u662F\\u963B\\u585E\\u7684\\uFF0C\\u4EE3\\u7801\\u6267\\u884C\\u4F1A\\u7B49\\u5F85\\u5B83\\u4EEC\\u5B8C\\u6210\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5F02\\u6B65\\u56DE\\u8C03\"}),\" \\u5728\\u5B8C\\u6210\\u67D0\\u4E2A\\u4E8B\\u4EF6\\u6216\\u64CD\\u4F5C\\u540E\\u6267\\u884C\\u3002\\u5B83\\u4EEC\\u662F\\u975E\\u963B\\u585E\\u7684\\uFF0C\\u5141\\u8BB8\\u4EE3\\u7801\\u6267\\u884C\\u5728\\u7B49\\u5F85\\u64CD\\u4F5C\\u5B8C\\u6210\\u7684\\u540C\\u65F6\\u7EE7\\u7EED\\u8FDB\\u884C\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u540C\\u6B65\\u56DE\\u8C03\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function greet(name, callback) {\n console.log('Hello ' + name);\n callback();\n}\n\nfunction sayGoodbye() {\n console.log('Goodbye!');\n}\n\ngreet('Alice', sayGoodbye);\n// Output:\n// Hello Alice\n// Goodbye!\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5F02\\u6B65\\u56DE\\u8C03\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n setTimeout(() => {\n const data = { name: 'John', age: 30 };\n callback(data);\n }, 1000);\n}\n\nfetchData((data) => {\n console.log(data);\n});\n// Output after 1 second:\n// { name: 'John', age: 30 }\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5E38\\u89C1\\u7528\\u4F8B\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7F51\\u7EDC\\u8BF7\\u6C42\"}),\"\\uFF1A\\u4ECE API \\u83B7\\u53D6\\u6570\\u636E\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6587\\u4EF6 I/O\"}),\"\\uFF1A\\u8BFB\\u53D6\\u6216\\u5199\\u5165\\u6587\\u4EF6\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u8BA1\\u65F6\\u5668\"}),\"\\uFF1A\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"setTimeout\"}),\" \\u6216 \",(0,e.jsx)(n.code,{children:\"setInterval\"}),\" \\u5EF6\\u8FDF\\u6267\\u884C\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E8B\\u4EF6\\u5904\\u7406\"}),\"\\uFF1A\\u54CD\\u5E94\\u7528\\u6237\\u64CD\\u4F5C\\uFF0C\\u5982\\u5355\\u51FB\\u6216\\u6309\\u952E\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5728\\u56DE\\u8C03\\u4E2D\\u5904\\u7406\\u9519\\u8BEF\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5904\\u7406\\u5F02\\u6B65\\u64CD\\u4F5C\\u65F6\\uFF0C\\u6B63\\u786E\\u5904\\u7406\\u9519\\u8BEF\\u975E\\u5E38\\u91CD\\u8981\\u3002\\u4E00\\u4E2A\\u5E38\\u89C1\\u7684\\u6A21\\u5F0F\\u662F\\u4F7F\\u7528\\u56DE\\u8C03\\u51FD\\u6570\\u7684\\u7B2C\\u4E00\\u4E2A\\u53C2\\u6570\\u6765\\u4F20\\u9012\\u4E00\\u4E2A\\u9519\\u8BEF\\u5BF9\\u8C61\\uFF08\\u5982\\u679C\\u6709\\uFF09\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`function fetchData(callback) {\n // assume asynchronous operation to fetch data\n const { data, error } = { data: { name: 'John', age: 30 }, error: null };\n callback(error, data);\n}\n\nfetchData((error, data) => {\n if (error) {\n console.error('An error occurred:', error);\n } else {\n console.log(data);\n }\n});\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Glossary/Callback_function\",children:\"MDN Web Docs: Callback function\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/callbacks\",children:\"JavaScript.info: Callbacks\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nodejs.org/en/learn/asynchronous-work/javascript-asynchronous-programming-and-callbacks\",children:\"Node.js: Asynchronous programming and callbacks\"})}),`\n`]})]})}function D(a={}){let{wrapper:n}=a.components||{};return n?(0,e.jsx)(n,Object.assign({},a,{children:(0,e.jsx)(h,a)})):h(a)}var v=D;return k(x);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-the-presentational-vs-container-component-pattern-in-react/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-the-presentational-vs-container-component-pattern-in-react/locales/en-US.json
index 82a567aee..afad9e9eb 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-the-presentational-vs-container-component-pattern-in-react/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-the-presentational-vs-container-component-pattern-in-react/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain the presentational vs container component pattern in React",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-the-presentational-vs-container-component-pattern-in-react/en-US.mdx"
},
- "solution": "var Component=(()=>{var d=Object.create;var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),b=(t,n)=>{for(var a in n)r(t,a,{get:n[a],enumerable:!0})},c=(t,n,a,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let o of m(n))!g.call(t,o)&&o!==a&&r(t,o,{get:()=>n[o],enumerable:!(i=p(n,o))||i.enumerable});return t};var x=(t,n,a)=>(a=t!=null?d(u(t)):{},c(n||!t||!t.__esModule?r(a,\"default\",{value:t,enumerable:!0}):a,t)),w=t=>c(r({},\"__esModule\",{value:!0}),t);var l=f((j,s)=>{s.exports=_jsx_runtime});var v={};b(v,{default:()=>k,frontmatter:()=>y});var e=x(l()),y={title:\"Explain the presentational vs container component pattern in React\"};function h(t){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",code:\"code\",h4:\"h4\",ul:\"ul\",li:\"li\",pre:\"pre\",strong:\"strong\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"In React, the presentational vs container component pattern is a design approach where presentational components focus on how things look and container components focus on how things work. Presentational components are concerned with rendering HTML and CSS, while container components handle the logic and state management. This separation helps in maintaining a clean and organized codebase.\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"Presentational vs container component pattern in React\"}),`\n`,(0,e.jsx)(n.h3,{children:\"Presentational components\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Presentational components are primarily concerned with the UI. They receive data and callbacks exclusively via props and rarely have their own state (except for UI state like \",(0,e.jsx)(n.code,{children:\"hover\"}),\" or \",(0,e.jsx)(n.code,{children:\"active\"}),\"). They are often stateless functional components but can also be class components.\"]}),`\n`,(0,e.jsx)(n.h4,{children:\"Characteristics\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"Focus on how things look\"}),`\n`,(0,e.jsx)(n.li,{children:\"Receive data and callbacks via props\"}),`\n`,(0,e.jsx)(n.li,{children:\"Rarely have their own state\"}),`\n`,(0,e.jsx)(n.li,{children:\"Typically written as functional components\"}),`\n`,(0,e.jsx)(n.li,{children:\"Do not use Redux or other state management libraries directly\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`const Button = ({ onClick, label }) => (\n {label} \n);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Container components\"}),`\n`,(0,e.jsx)(n.p,{children:\"Container components are concerned with how things work. They manage state and handle business logic. They often fetch data, handle user interactions, and pass data down to presentational components as props.\"}),`\n`,(0,e.jsx)(n.h4,{children:\"Characteristics\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"Focus on how things work\"}),`\n`,(0,e.jsx)(n.li,{children:\"Manage state and handle business logic\"}),`\n`,(0,e.jsx)(n.li,{children:\"Fetch data and handle user interactions\"}),`\n`,(0,e.jsx)(n.li,{children:\"Pass data and callbacks to presentational components\"}),`\n`,(0,e.jsx)(n.li,{children:\"Often use Redux or other state management libraries\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React, { Component } from 'react';\nimport { connect } from 'react-redux';\nimport { fetchData } from './actions';\nimport Button from './Button';\n\nclass ButtonContainer extends Component {\n componentDidMount() {\n this.props.fetchData();\n }\n\n handleClick = () => {\n // Handle button click\n };\n\n render() {\n return ;\n }\n}\n\nconst mapDispatchToProps = {\n fetchData,\n};\n\nexport default connect(null, mapDispatchToProps)(ButtonContainer);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Benefits\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Separation of concerns\"}),\": By separating the UI from the logic, the codebase becomes more modular and easier to maintain.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Reusability\"}),\": Presentational components can be reused across different parts of the application since they are not tied to specific logic.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Testability\"}),\": Presentational components are easier to test because they are stateless and only rely on props.\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/components-and-props.html\",children:\"React documentation on components and props\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\",children:\"Dan Abramov's article on presentational and container components\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://redux.js.org/basics/usage-with-react#presentational-and-container-components\",children:\"Redux documentation on presentational and container components\"})}),`\n`]})]})}function C(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(h,t)})):h(t)}var k=C;return w(v);})();\n;return Component;"
+ "solution": "var Component=(()=>{var d=Object.create;var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),b=(t,n)=>{for(var a in n)r(t,a,{get:n[a],enumerable:!0})},c=(t,n,a,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let o of m(n))!g.call(t,o)&&o!==a&&r(t,o,{get:()=>n[o],enumerable:!(i=p(n,o))||i.enumerable});return t};var x=(t,n,a)=>(a=t!=null?d(u(t)):{},c(n||!t||!t.__esModule?r(a,\"default\",{value:t,enumerable:!0}):a,t)),w=t=>c(r({},\"__esModule\",{value:!0}),t);var l=f((D,s)=>{s.exports=_jsx_runtime});var v={};b(v,{default:()=>k,frontmatter:()=>y});var e=x(l()),y={title:\"Explain the presentational vs container component pattern in React\"};function h(t){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",code:\"code\",h4:\"h4\",ul:\"ul\",li:\"li\",pre:\"pre\",strong:\"strong\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"In React, the presentational vs container component pattern is a design approach where presentational components focus on how things look and container components focus on how things work. Presentational components are concerned with rendering HTML and CSS, while container components handle the logic and state management. This separation helps in maintaining a clean and organized codebase.\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"Presentational vs container component pattern in React\"}),`\n`,(0,e.jsx)(n.h3,{children:\"Presentational components\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"Presentational components are primarily concerned with the UI. They receive data and callbacks exclusively via props and rarely have their own state (except for UI state like \",(0,e.jsx)(n.code,{children:\"hover\"}),\" or \",(0,e.jsx)(n.code,{children:\"active\"}),\"). They are often stateless functional components but can also be class components.\"]}),`\n`,(0,e.jsx)(n.h4,{children:\"Characteristics\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"Focus on how things look\"}),`\n`,(0,e.jsx)(n.li,{children:\"Receive data and callbacks via props\"}),`\n`,(0,e.jsx)(n.li,{children:\"Rarely have their own state\"}),`\n`,(0,e.jsx)(n.li,{children:\"Typically written as functional components\"}),`\n`,(0,e.jsx)(n.li,{children:\"Do not use Redux or other state management libraries directly\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`const Button = ({ onClick, label }) => (\n {label} \n);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Container components\"}),`\n`,(0,e.jsx)(n.p,{children:\"Container components are concerned with how things work. They manage state and handle business logic. They often fetch data, handle user interactions, and pass data down to presentational components as props.\"}),`\n`,(0,e.jsx)(n.h4,{children:\"Characteristics\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"Focus on how things work\"}),`\n`,(0,e.jsx)(n.li,{children:\"Manage state and handle business logic\"}),`\n`,(0,e.jsx)(n.li,{children:\"Fetch data and handle user interactions\"}),`\n`,(0,e.jsx)(n.li,{children:\"Pass data and callbacks to presentational components\"}),`\n`,(0,e.jsx)(n.li,{children:\"Often use Redux or other state management libraries\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React, { Component } from 'react';\nimport { connect } from 'react-redux';\nimport { fetchData } from './actions';\nimport Button from './Button';\n\nclass ButtonContainer extends Component {\n componentDidMount() {\n this.props.fetchData();\n }\n\n handleClick = () => {\n // Handle button click\n };\n\n render() {\n return ;\n }\n}\n\nconst mapDispatchToProps = {\n fetchData,\n};\n\nexport default connect(null, mapDispatchToProps)(ButtonContainer);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Benefits\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Separation of concerns\"}),\": By separating the UI from the logic, the codebase becomes more modular and easier to maintain.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Reusability\"}),\": Presentational components can be reused across different parts of the application since they are not tied to specific logic.\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Testability\"}),\": Presentational components are easier to test because they are stateless and only rely on props.\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/learn/passing-props-to-a-component\",children:\"React documentation on components and props\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\",children:\"Dan Abramov's article on presentational and container components\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://redux.js.org/basics/usage-with-react#presentational-and-container-components\",children:\"Redux documentation on presentational and container components\"})}),`\n`]})]})}function C(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(h,t)})):h(t)}var k=C;return w(v);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-the-presentational-vs-container-component-pattern-in-react/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-the-presentational-vs-container-component-pattern-in-react/locales/zh-CN.json
index 4832e0373..ca0f02021 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-the-presentational-vs-container-component-pattern-in-react/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-the-presentational-vs-container-component-pattern-in-react/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释 React 中的展示组件与容器组件模式",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-the-presentational-vs-container-component-pattern-in-react/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var f=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),g=(r,n)=>{for(var c in n)l(r,c,{get:n[c],enumerable:!0})},o=(r,n,c,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of m(n))!x.call(r,t)&&t!==c&&l(r,t,{get:()=>n[t],enumerable:!(i=p(n,t))||i.enumerable});return r};var C=(r,n,c)=>(c=r!=null?s(u(r)):{},o(n||!r||!r.__esModule?l(c,\"default\",{value:r,enumerable:!0}):c,r)),b=r=>o(l({},\"__esModule\",{value:!0}),r);var d=f((B,h)=>{h.exports=_jsx_runtime});var k={};g(k,{default:()=>R,frontmatter:()=>j});var e=C(d()),j={title:\"\\u89E3\\u91CA React \\u4E2D\\u7684\\u5C55\\u793A\\u7EC4\\u4EF6\\u4E0E\\u5BB9\\u5668\\u7EC4\\u4EF6\\u6A21\\u5F0F\"};function a(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",code:\"code\",h4:\"h4\",ul:\"ul\",li:\"li\",pre:\"pre\",strong:\"strong\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5728 React \\u4E2D\\uFF0C\\u5C55\\u793A\\u7EC4\\u4EF6\\u4E0E\\u5BB9\\u5668\\u7EC4\\u4EF6\\u6A21\\u5F0F\\u662F\\u4E00\\u79CD\\u8BBE\\u8BA1\\u65B9\\u6CD5\\uFF0C\\u5176\\u4E2D\\u5C55\\u793A\\u7EC4\\u4EF6\\u4FA7\\u91CD\\u4E8E\\u5916\\u89C2\\uFF0C\\u800C\\u5BB9\\u5668\\u7EC4\\u4EF6\\u4FA7\\u91CD\\u4E8E\\u5DE5\\u4F5C\\u65B9\\u5F0F\\u3002\\u5C55\\u793A\\u7EC4\\u4EF6\\u8D1F\\u8D23\\u6E32\\u67D3 HTML \\u548C CSS\\uFF0C\\u800C\\u5BB9\\u5668\\u7EC4\\u4EF6\\u5904\\u7406\\u903B\\u8F91\\u548C\\u72B6\\u6001\\u7BA1\\u7406\\u3002\\u8FD9\\u79CD\\u5206\\u79BB\\u6709\\u52A9\\u4E8E\\u7EF4\\u62A4\\u5E72\\u51C0\\u548C\\u6709\\u7EC4\\u7EC7\\u7684 codebase\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"React \\u4E2D\\u7684\\u5C55\\u793A\\u7EC4\\u4EF6\\u4E0E\\u5BB9\\u5668\\u7EC4\\u4EF6\\u6A21\\u5F0F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5C55\\u793A\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5C55\\u793A\\u7EC4\\u4EF6\\u4E3B\\u8981\\u5173\\u6CE8 UI\\u3002\\u5B83\\u4EEC\\u4EC5\\u901A\\u8FC7 props \\u63A5\\u6536\\u6570\\u636E\\u548C\\u56DE\\u8C03\\uFF0C\\u5E76\\u4E14\\u5F88\\u5C11\\u6709\\u81EA\\u5DF1\\u7684\\u72B6\\u6001\\uFF08\\u9664\\u4E86 UI \\u72B6\\u6001\\uFF0C\\u5982 \",(0,e.jsx)(n.code,{children:\"hover\"}),\" \\u6216 \",(0,e.jsx)(n.code,{children:\"active\"}),\"\\uFF09\\u3002\\u5B83\\u4EEC\\u901A\\u5E38\\u662F\\u65E0\\u72B6\\u6001\\u51FD\\u6570\\u7EC4\\u4EF6\\uFF0C\\u4F46\\u4E5F\\u53EF\\u4EE5\\u662F\\u7C7B\\u7EC4\\u4EF6\\u3002\"]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u7279\\u70B9\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5173\\u6CE8\\u5916\\u89C2\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u901A\\u8FC7 props \\u63A5\\u6536\\u6570\\u636E\\u548C\\u56DE\\u8C03\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F88\\u5C11\\u6709\\u81EA\\u5DF1\\u7684\\u72B6\\u6001\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u901A\\u5E38\\u5199\\u6210\\u51FD\\u6570\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4E0D\\u76F4\\u63A5\\u4F7F\\u7528 Redux \\u6216\\u5176\\u4ED6\\u72B6\\u6001\\u7BA1\\u7406\\u5E93\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`const Button = ({ onClick, label }) => (\n {label} \n);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5BB9\\u5668\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5BB9\\u5668\\u7EC4\\u4EF6\\u5173\\u6CE8\\u4E8E\\u5DE5\\u4F5C\\u65B9\\u5F0F\\u3002\\u5B83\\u4EEC\\u7BA1\\u7406\\u72B6\\u6001\\u5E76\\u5904\\u7406\\u4E1A\\u52A1\\u903B\\u8F91\\u3002\\u5B83\\u4EEC\\u901A\\u5E38\\u83B7\\u53D6\\u6570\\u636E\\u3001\\u5904\\u7406\\u7528\\u6237\\u4EA4\\u4E92\\uFF0C\\u5E76\\u5C06\\u6570\\u636E\\u4F5C\\u4E3A props \\u4F20\\u9012\\u7ED9\\u5C55\\u793A\\u7EC4\\u4EF6\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u7279\\u70B9\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5173\\u6CE8\\u5DE5\\u4F5C\\u65B9\\u5F0F\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u7BA1\\u7406\\u72B6\\u6001\\u5E76\\u5904\\u7406\\u4E1A\\u52A1\\u903B\\u8F91\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u83B7\\u53D6\\u6570\\u636E\\u5E76\\u5904\\u7406\\u7528\\u6237\\u4EA4\\u4E92\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u6570\\u636E\\u548C\\u56DE\\u8C03\\u4F20\\u9012\\u7ED9\\u5C55\\u793A\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u7ECF\\u5E38\\u4F7F\\u7528 Redux \\u6216\\u5176\\u4ED6\\u72B6\\u6001\\u7BA1\\u7406\\u5E93\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React, { Component } from 'react';\nimport { connect } from 'react-redux';\nimport { fetchData } from './actions';\nimport Button from './Button';\n\nclass ButtonContainer extends Component {\n componentDidMount() {\n this.props.fetchData();\n }\n\n handleClick = () => {\n // Handle button click\n };\n\n render() {\n return ;\n }\n}\n\nconst mapDispatchToProps = {\n fetchData,\n};\n\nexport default connect(null, mapDispatchToProps)(ButtonContainer);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4F18\\u70B9\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5173\\u6CE8\\u70B9\\u5206\\u79BB\"}),\"\\uFF1A\\u901A\\u8FC7\\u5C06 UI \\u4E0E\\u903B\\u8F91\\u5206\\u79BB\\uFF0C\\u4EE3\\u7801\\u5E93\\u53D8\\u5F97\\u66F4\\u52A0\\u6A21\\u5757\\u5316\\uFF0C\\u66F4\\u6613\\u4E8E\\u7EF4\\u62A4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53EF\\u91CD\\u7528\\u6027\"}),\"\\uFF1A\\u5C55\\u793A\\u7EC4\\u4EF6\\u53EF\\u4EE5\\u5728\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u4E0D\\u540C\\u90E8\\u5206\\u91CD\\u590D\\u4F7F\\u7528\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u4E0D\\u4E0E\\u7279\\u5B9A\\u903B\\u8F91\\u76F8\\u5173\\u8054\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53EF\\u6D4B\\u8BD5\\u6027\"}),\"\\uFF1A\\u5C55\\u793A\\u7EC4\\u4EF6\\u66F4\\u5BB9\\u6613\\u6D4B\\u8BD5\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u662F\\u65E0\\u72B6\\u6001\\u7684\\uFF0C\\u5E76\\u4E14\\u4EC5\\u4F9D\\u8D56\\u4E8E props\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/components-and-props.html\",children:\"React \\u7EC4\\u4EF6\\u548C props \\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\",children:\"Dan Abramov \\u5173\\u4E8E\\u5C55\\u793A\\u7EC4\\u4EF6\\u548C\\u5BB9\\u5668\\u7EC4\\u4EF6\\u7684\\u6587\\u7AE0\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://redux.js.org/basics/usage-with-react#presentational-and-container-components\",children:\"Redux \\u5173\\u4E8E\\u5C55\\u793A\\u7EC4\\u4EF6\\u548C\\u5BB9\\u5668\\u7EC4\\u4EF6\\u7684\\u6587\\u6863\"})}),`\n`]})]})}function D(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(a,r)})):a(r)}var R=D;return b(k);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var f=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),g=(t,n)=>{for(var r in n)o(t,r,{get:n[r],enumerable:!0})},l=(t,n,r,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of m(n))!x.call(t,c)&&c!==r&&o(t,c,{get:()=>n[c],enumerable:!(i=p(n,c))||i.enumerable});return t};var C=(t,n,r)=>(r=t!=null?s(u(t)):{},l(n||!t||!t.__esModule?o(r,\"default\",{value:t,enumerable:!0}):r,t)),b=t=>l(o({},\"__esModule\",{value:!0}),t);var h=f((B,a)=>{a.exports=_jsx_runtime});var k={};g(k,{default:()=>R,frontmatter:()=>j});var e=C(h()),j={title:\"\\u89E3\\u91CA React \\u4E2D\\u7684\\u5C55\\u793A\\u7EC4\\u4EF6\\u4E0E\\u5BB9\\u5668\\u7EC4\\u4EF6\\u6A21\\u5F0F\"};function d(t){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",code:\"code\",h4:\"h4\",ul:\"ul\",li:\"li\",pre:\"pre\",strong:\"strong\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5728 React \\u4E2D\\uFF0C\\u5C55\\u793A\\u7EC4\\u4EF6\\u4E0E\\u5BB9\\u5668\\u7EC4\\u4EF6\\u6A21\\u5F0F\\u662F\\u4E00\\u79CD\\u8BBE\\u8BA1\\u65B9\\u6CD5\\uFF0C\\u5176\\u4E2D\\u5C55\\u793A\\u7EC4\\u4EF6\\u4FA7\\u91CD\\u4E8E\\u5916\\u89C2\\uFF0C\\u800C\\u5BB9\\u5668\\u7EC4\\u4EF6\\u4FA7\\u91CD\\u4E8E\\u5DE5\\u4F5C\\u65B9\\u5F0F\\u3002\\u5C55\\u793A\\u7EC4\\u4EF6\\u8D1F\\u8D23\\u6E32\\u67D3 HTML \\u548C CSS\\uFF0C\\u800C\\u5BB9\\u5668\\u7EC4\\u4EF6\\u5904\\u7406\\u903B\\u8F91\\u548C\\u72B6\\u6001\\u7BA1\\u7406\\u3002\\u8FD9\\u79CD\\u5206\\u79BB\\u6709\\u52A9\\u4E8E\\u7EF4\\u62A4\\u5E72\\u51C0\\u548C\\u6709\\u7EC4\\u7EC7\\u7684 codebase\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"React \\u4E2D\\u7684\\u5C55\\u793A\\u7EC4\\u4EF6\\u4E0E\\u5BB9\\u5668\\u7EC4\\u4EF6\\u6A21\\u5F0F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5C55\\u793A\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5C55\\u793A\\u7EC4\\u4EF6\\u4E3B\\u8981\\u5173\\u6CE8 UI\\u3002\\u5B83\\u4EEC\\u4EC5\\u901A\\u8FC7 props \\u63A5\\u6536\\u6570\\u636E\\u548C\\u56DE\\u8C03\\uFF0C\\u5E76\\u4E14\\u5F88\\u5C11\\u6709\\u81EA\\u5DF1\\u7684\\u72B6\\u6001\\uFF08\\u9664\\u4E86 UI \\u72B6\\u6001\\uFF0C\\u5982 \",(0,e.jsx)(n.code,{children:\"hover\"}),\" \\u6216 \",(0,e.jsx)(n.code,{children:\"active\"}),\"\\uFF09\\u3002\\u5B83\\u4EEC\\u901A\\u5E38\\u662F\\u65E0\\u72B6\\u6001\\u51FD\\u6570\\u7EC4\\u4EF6\\uFF0C\\u4F46\\u4E5F\\u53EF\\u4EE5\\u662F\\u7C7B\\u7EC4\\u4EF6\\u3002\"]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u7279\\u70B9\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5173\\u6CE8\\u5916\\u89C2\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u901A\\u8FC7 props \\u63A5\\u6536\\u6570\\u636E\\u548C\\u56DE\\u8C03\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F88\\u5C11\\u6709\\u81EA\\u5DF1\\u7684\\u72B6\\u6001\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u901A\\u5E38\\u5199\\u6210\\u51FD\\u6570\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u4E0D\\u76F4\\u63A5\\u4F7F\\u7528 Redux \\u6216\\u5176\\u4ED6\\u72B6\\u6001\\u7BA1\\u7406\\u5E93\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`const Button = ({ onClick, label }) => (\n {label} \n);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5BB9\\u5668\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5BB9\\u5668\\u7EC4\\u4EF6\\u5173\\u6CE8\\u4E8E\\u5DE5\\u4F5C\\u65B9\\u5F0F\\u3002\\u5B83\\u4EEC\\u7BA1\\u7406\\u72B6\\u6001\\u5E76\\u5904\\u7406\\u4E1A\\u52A1\\u903B\\u8F91\\u3002\\u5B83\\u4EEC\\u901A\\u5E38\\u83B7\\u53D6\\u6570\\u636E\\u3001\\u5904\\u7406\\u7528\\u6237\\u4EA4\\u4E92\\uFF0C\\u5E76\\u5C06\\u6570\\u636E\\u4F5C\\u4E3A props \\u4F20\\u9012\\u7ED9\\u5C55\\u793A\\u7EC4\\u4EF6\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u7279\\u70B9\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5173\\u6CE8\\u5DE5\\u4F5C\\u65B9\\u5F0F\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u7BA1\\u7406\\u72B6\\u6001\\u5E76\\u5904\\u7406\\u4E1A\\u52A1\\u903B\\u8F91\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u83B7\\u53D6\\u6570\\u636E\\u5E76\\u5904\\u7406\\u7528\\u6237\\u4EA4\\u4E92\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5C06\\u6570\\u636E\\u548C\\u56DE\\u8C03\\u4F20\\u9012\\u7ED9\\u5C55\\u793A\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u7ECF\\u5E38\\u4F7F\\u7528 Redux \\u6216\\u5176\\u4ED6\\u72B6\\u6001\\u7BA1\\u7406\\u5E93\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F8B\\u5B50\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React, { Component } from 'react';\nimport { connect } from 'react-redux';\nimport { fetchData } from './actions';\nimport Button from './Button';\n\nclass ButtonContainer extends Component {\n componentDidMount() {\n this.props.fetchData();\n }\n\n handleClick = () => {\n // Handle button click\n };\n\n render() {\n return ;\n }\n}\n\nconst mapDispatchToProps = {\n fetchData,\n};\n\nexport default connect(null, mapDispatchToProps)(ButtonContainer);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4F18\\u70B9\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5173\\u6CE8\\u70B9\\u5206\\u79BB\"}),\"\\uFF1A\\u901A\\u8FC7\\u5C06 UI \\u4E0E\\u903B\\u8F91\\u5206\\u79BB\\uFF0C\\u4EE3\\u7801\\u5E93\\u53D8\\u5F97\\u66F4\\u52A0\\u6A21\\u5757\\u5316\\uFF0C\\u66F4\\u6613\\u4E8E\\u7EF4\\u62A4\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53EF\\u91CD\\u7528\\u6027\"}),\"\\uFF1A\\u5C55\\u793A\\u7EC4\\u4EF6\\u53EF\\u4EE5\\u5728\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u4E0D\\u540C\\u90E8\\u5206\\u91CD\\u590D\\u4F7F\\u7528\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u4E0D\\u4E0E\\u7279\\u5B9A\\u903B\\u8F91\\u76F8\\u5173\\u8054\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53EF\\u6D4B\\u8BD5\\u6027\"}),\"\\uFF1A\\u5C55\\u793A\\u7EC4\\u4EF6\\u66F4\\u5BB9\\u6613\\u6D4B\\u8BD5\\uFF0C\\u56E0\\u4E3A\\u5B83\\u4EEC\\u662F\\u65E0\\u72B6\\u6001\\u7684\\uFF0C\\u5E76\\u4E14\\u4EC5\\u4F9D\\u8D56\\u4E8E props\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/learn/passing-props-to-a-component\",children:\"React documentation on components and props\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0\",children:\"Dan Abramov's article on presentational and container components\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://redux.js.org/basics/usage-with-react#presentational-and-container-components\",children:\"Redux documentation on presentational and container components\"})}),`\n`]})]})}function D(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(d,t)})):d(t)}var R=D;return b(k);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-what-happens-when-setstate-is-called-in-react/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-what-happens-when-setstate-is-called-in-react/locales/en-US.json
index 51b590a57..cd020021e 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-what-happens-when-setstate-is-called-in-react/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-what-happens-when-setstate-is-called-in-react/locales/en-US.json
@@ -2,8 +2,8 @@
"description": null,
"info": {
"excerpt": null,
- "title": "Explain what happens when `setState` is called in React",
+ "title": "Explain what happens when the `useState` setter function is called in React",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-what-happens-when-setstate-is-called-in-react/en-US.mdx"
},
- "solution": "var Component=(()=>{var l=Object.create;var s=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),S=(n,e)=>{for(var a in e)s(n,a,{get:e[a],enumerable:!0})},r=(n,e,a,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of m(e))!g.call(n,c)&&c!==a&&s(n,c,{get:()=>e[c],enumerable:!(h=p(e,c))||h.enumerable});return n};var R=(n,e,a)=>(a=n!=null?l(u(n)):{},r(e||!n||!n.__esModule?s(a,\"default\",{value:n,enumerable:!0}):a,n)),w=n=>r(s({},\"__esModule\",{value:!0}),n);var d=f((M,i)=>{i.exports=_jsx_runtime});var x={};S(x,{default:()=>y,frontmatter:()=>b});var t=R(d()),b={title:\"Explain what happens when `setState` is called in React\"};function o(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",pre:\"pre\",ul:\"ul\",li:\"li\",a:\"a\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"When \",(0,t.jsx)(e.code,{children:\"setState\"}),\" is called in React, it schedules an update to the component's state object. React then merges the new state with the current state and triggers a re-render of the component. This process is asynchronous, meaning the state change might not happen immediately. React batches multiple \",(0,t.jsx)(e.code,{children:\"setState\"}),\" calls for performance optimization.\"]}),`\n`,(0,t.jsx)(e.hr,{}),`\n`,(0,t.jsxs)(e.h2,{children:[\"What happens when \",(0,t.jsx)(e.code,{children:\"setState\"}),\" is called in React\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"State update scheduling\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"When \",(0,t.jsx)(e.code,{children:\"setState\"}),\" is called, React schedules an update to the component's state. This means that the state change does not happen immediately. Instead, React marks the component as needing an update and will process the state change later.\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`this.setState({ count: this.state.count + 1 });\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"Merging state\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"React merges the new state with the current state. The \",(0,t.jsx)(e.code,{children:\"setState\"}),\" method performs a shallow merge, meaning it only updates the properties specified in the new state object and leaves the rest unchanged.\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`this.setState({ name: 'John' });\n// Only the 'name' property is updated, other state properties remain the same\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"Re-rendering\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"After merging the state, React triggers a re-render of the component. The component's \",(0,t.jsx)(e.code,{children:\"render\"}),\" method is called, and the virtual DOM is updated. React then compares the virtual DOM with the actual DOM and makes the necessary updates to the actual DOM.\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"Asynchronous nature\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"The \",(0,t.jsx)(e.code,{children:\"setState\"}),\" method is asynchronous. React batches multiple \",(0,t.jsx)(e.code,{children:\"setState\"}),\" calls for performance optimization. This means that if you call \",(0,t.jsx)(e.code,{children:\"setState\"}),\" multiple times in a row, React may combine them into a single update.\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`this.setState({ count: this.state.count + 1 });\nthis.setState({ count: this.state.count + 1 });\n// React may batch these updates into a single update\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"Callback function\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"You can pass a callback function as the second argument to \",(0,t.jsx)(e.code,{children:\"setState\"}),\". This function will be called after the state has been updated and the component has re-rendered.\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`this.setState({ count: this.state.count + 1 }, () => {\n console.log('State updated and component re-rendered');\n});\n`})}),`\n`,(0,t.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:(0,t.jsx)(e.a,{href:\"https://reactjs.org/docs/react-component.html#setstate\",children:\"React documentation on setState\"})}),`\n`,(0,t.jsx)(e.li,{children:(0,t.jsx)(e.a,{href:\"https://medium.com/@baphemot/understanding-react-setstate-a4640451865b\",children:\"Understanding setState in React\"})}),`\n`,(0,t.jsx)(e.li,{children:(0,t.jsx)(e.a,{href:\"https://daveceddia.com/where-fetch-data-componentwillmount-vs-componentdidmount/\",children:\"React's setState explained\"})}),`\n`]})]})}function j(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(o,n)})):o(n)}var y=j;return w(x);})();\n;return Component;"
+ "solution": "var Component=(()=>{var l=Object.create;var r=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),y=(n,e)=>{for(var a in e)r(n,a,{get:e[a],enumerable:!0})},c=(n,e,a,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let s of p(e))!g.call(n,s)&&s!==a&&r(n,s,{get:()=>e[s],enumerable:!(o=d(e,s))||o.enumerable});return n};var v=(n,e,a)=>(a=n!=null?l(f(n)):{},c(e||!n||!n.__esModule?r(a,\"default\",{value:n,enumerable:!0}):a,n)),w=n=>c(r({},\"__esModule\",{value:!0}),n);var h=m((x,u)=>{u.exports=_jsx_runtime});var C={};y(C,{default:()=>R,frontmatter:()=>b});var t=v(h()),b={title:\"Explain what happens when the `useState` setter function is called in React\"};function i(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",pre:\"pre\",strong:\"strong\",ul:\"ul\",li:\"li\",a:\"a\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"When the setter function returned by the \",(0,t.jsx)(e.code,{children:\"useState\"}),\" hook is called in React, it schedules an update to the component's state value. React then queues a re-render of the component with the new state. This process is typically asynchronous, and React batches multiple state updates together for performance.\"]}),`\n`,(0,t.jsx)(e.hr,{}),`\n`,(0,t.jsxs)(e.h2,{children:[\"What happens when the \",(0,t.jsx)(e.code,{children:\"useState\"}),\" setter is called\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"State update scheduling\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"When you call the setter function provided by \",(0,t.jsx)(e.code,{children:\"useState\"}),\" (e.g., \",(0,t.jsx)(e.code,{children:\"setCount\"}),\"), React schedules an update for that specific state variable. This doesn't happen instantly; React marks the component as needing to re-render with the updated state value.\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`const [count, setCount] = useState(0);\n// ...\nsetCount(count + 1); // Schedules an update to set 'count' to 1\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"State replacement\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"The \",(0,t.jsx)(e.code,{children:\"useState\"}),\" setter function \",(0,t.jsx)(e.strong,{children:\"replaces\"}),\" the old state value entirely with the new value you provide. If your state is an object and you only want to update one property, you need to manually spread the old state and override the specific property.\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`const [user, setUser] = useState({ name: 'Anon', age: 99 });\n\n// To update only name, you must spread the old state:\nsetUser((prevState) => ({ ...prevState, name: 'John' }));\n// If you just did setUser({ name: 'John' }), the 'age' property would be lost.\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"Re-rendering\"}),`\n`,(0,t.jsx)(e.p,{children:\"After scheduling the state update(s), React will eventually trigger a re-render of the component. The functional component body is executed again with the new state value(s). React updates its virtual DOM, compares it with the previous version, and efficiently updates the actual DOM only where necessary.\"}),`\n`,(0,t.jsx)(e.h3,{children:\"Asynchronous nature and Batching\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"State updates triggered by \",(0,t.jsx)(e.code,{children:\"useState\"}),\" setters are typically asynchronous and batched. If you call multiple state setters in the same event handler or effect, React will often batch these updates together into a single re-render pass for better performance. Because of this, you shouldn't rely on the state variable having its new value immediately after calling the setter. If the new state depends on the previous state, use the functional update form.\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`// Assume count is 0\nsetCount(count + 1); // Queues update to 1\nsetCount(count + 1); // Still sees count as 0, queues update to 1 again!\n// Result might be 1, not 2\n\n// Correct way using functional update:\nsetCount((prevCount) => prevCount + 1); // Queues update based on previous state\nsetCount((prevCount) => prevCount + 1); // Queues another update based on the result of the first\n// Result will be 2\n`})}),`\n`,(0,t.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:(0,t.jsxs)(e.a,{href:\"https://react.dev/reference/react/useState\",children:[\"React Docs: Using the State Hook (\",(0,t.jsx)(e.code,{children:\"useState\"}),\")\"]})}),`\n`,(0,t.jsx)(e.li,{children:(0,t.jsx)(e.a,{href:\"https://react.dev/reference/react/useState#updating-state-based-on-the-previous-state\",children:\"React Docs: Queueing multiple state updates\"})}),`\n`]})]})}function S(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(i,n)})):i(n)}var R=S;return w(C);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-what-happens-when-setstate-is-called-in-react/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-what-happens-when-setstate-is-called-in-react/locales/zh-CN.json
index 424e59a2b..a0effa10e 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-what-happens-when-setstate-is-called-in-react/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-what-happens-when-setstate-is-called-in-react/locales/zh-CN.json
@@ -2,8 +2,8 @@
"description": null,
"info": {
"excerpt": null,
- "title": "解释在 React 中调用 `setState` 时会发生什么",
+ "title": "解释在 React 中调用 `useState` 设置器函数时会发生什么",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-what-happens-when-setstate-is-called-in-react/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var o=Object.create;var r=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var R=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),g=(n,e)=>{for(var c in e)r(n,c,{get:e[c],enumerable:!0})},s=(n,e,c,h)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of m(e))!S.call(n,a)&&a!==c&&r(n,a,{get:()=>e[a],enumerable:!(h=p(e,a))||h.enumerable});return n};var j=(n,e,c)=>(c=n!=null?o(u(n)):{},s(e||!n||!n.__esModule?r(c,\"default\",{value:n,enumerable:!0}):c,n)),f=n=>s(r({},\"__esModule\",{value:!0}),n);var d=R((O,i)=>{i.exports=_jsx_runtime});var v={};g(v,{default:()=>_,frontmatter:()=>x});var t=j(d()),x={title:\"\\u89E3\\u91CA\\u5728 React \\u4E2D\\u8C03\\u7528 `setState` \\u65F6\\u4F1A\\u53D1\\u751F\\u4EC0\\u4E48\"};function l(n){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",pre:\"pre\",ul:\"ul\",li:\"li\",a:\"a\"},n.components);return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e.h2,{children:\"\\u603B\\u7ED3\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u5728 React \\u4E2D\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"setState\"}),\" \\u65F6\\uFF0C\\u5B83\\u4F1A\\u5B89\\u6392\\u5BF9\\u7EC4\\u4EF6\\u72B6\\u6001\\u5BF9\\u8C61\\u7684\\u66F4\\u65B0\\u3002\\u7136\\u540E\\uFF0CReact \\u5C06\\u65B0\\u72B6\\u6001\\u4E0E\\u5F53\\u524D\\u72B6\\u6001\\u5408\\u5E76\\uFF0C\\u5E76\\u89E6\\u53D1\\u7EC4\\u4EF6\\u7684\\u91CD\\u65B0\\u6E32\\u67D3\\u3002\\u6B64\\u8FC7\\u7A0B\\u662F\\u5F02\\u6B65\\u7684\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u72B6\\u6001\\u66F4\\u6539\\u53EF\\u80FD\\u4E0D\\u4F1A\\u7ACB\\u5373\\u53D1\\u751F\\u3002React \\u4F1A\\u6279\\u91CF\\u5904\\u7406\\u591A\\u4E2A \",(0,t.jsx)(e.code,{children:\"setState\"}),\" \\u8C03\\u7528\\u4EE5\\u8FDB\\u884C\\u6027\\u80FD\\u4F18\\u5316\\u3002\"]}),`\n`,(0,t.jsx)(e.hr,{}),`\n`,(0,t.jsxs)(e.h2,{children:[\"\\u5728 React \\u4E2D\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"setState\"}),\" \\u65F6\\u4F1A\\u53D1\\u751F\\u4EC0\\u4E48\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u72B6\\u6001\\u66F4\\u65B0\\u8C03\\u5EA6\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u5F53\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"setState\"}),\" \\u65F6\\uFF0CReact \\u4F1A\\u5B89\\u6392\\u5BF9\\u7EC4\\u4EF6\\u72B6\\u6001\\u7684\\u66F4\\u65B0\\u3002\\u8FD9\\u610F\\u5473\\u7740\\u72B6\\u6001\\u66F4\\u6539\\u4E0D\\u4F1A\\u7ACB\\u5373\\u53D1\\u751F\\u3002\\u76F8\\u53CD\\uFF0CReact \\u4F1A\\u5C06\\u7EC4\\u4EF6\\u6807\\u8BB0\\u4E3A\\u9700\\u8981\\u66F4\\u65B0\\uFF0C\\u7A0D\\u540E\\u5C06\\u5904\\u7406\\u72B6\\u6001\\u66F4\\u6539\\u3002\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`this.setState({ count: this.state.count + 1 });\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u5408\\u5E76\\u72B6\\u6001\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"React \\u5C06\\u65B0\\u72B6\\u6001\\u4E0E\\u5F53\\u524D\\u72B6\\u6001\\u5408\\u5E76\\u3002\",(0,t.jsx)(e.code,{children:\"setState\"}),\" \\u65B9\\u6CD5\\u6267\\u884C\\u6D45\\u5408\\u5E76\\uFF0C\\u8FD9\\u610F\\u5473\\u7740\\u5B83\\u4EC5\\u66F4\\u65B0\\u65B0\\u72B6\\u6001\\u5BF9\\u8C61\\u4E2D\\u6307\\u5B9A\\u7684\\u5C5E\\u6027\\uFF0C\\u800C\\u4FDD\\u7559\\u5176\\u4F59\\u5C5E\\u6027\\u4E0D\\u53D8\\u3002\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`this.setState({ name: 'John' });\n// \\u4EC5\\u66F4\\u65B0 'name' \\u5C5E\\u6027\\uFF0C\\u5176\\u4ED6\\u72B6\\u6001\\u5C5E\\u6027\\u4FDD\\u6301\\u4E0D\\u53D8\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u91CD\\u65B0\\u6E32\\u67D3\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u5408\\u5E76\\u72B6\\u6001\\u540E\\uFF0CReact \\u4F1A\\u89E6\\u53D1\\u7EC4\\u4EF6\\u7684\\u91CD\\u65B0\\u6E32\\u67D3\\u3002\\u5C06\\u8C03\\u7528\\u7EC4\\u4EF6\\u7684 \",(0,t.jsx)(e.code,{children:\"render\"}),\" \\u65B9\\u6CD5\\uFF0C\\u5E76\\u66F4\\u65B0\\u865A\\u62DF DOM\\u3002\\u7136\\u540E\\uFF0CReact \\u5C06\\u865A\\u62DF DOM \\u4E0E\\u5B9E\\u9645 DOM \\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5E76\\u5BF9\\u5B9E\\u9645 DOM \\u8FDB\\u884C\\u5FC5\\u8981\\u7684\\u66F4\\u65B0\\u3002\"]}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u5F02\\u6B65\\u6027\\u8D28\"}),`\n`,(0,t.jsxs)(e.p,{children:[(0,t.jsx)(e.code,{children:\"setState\"}),\" \\u65B9\\u6CD5\\u662F\\u5F02\\u6B65\\u7684\\u3002React \\u4F1A\\u6279\\u91CF\\u5904\\u7406\\u591A\\u4E2A \",(0,t.jsx)(e.code,{children:\"setState\"}),\" \\u8C03\\u7528\\u4EE5\\u8FDB\\u884C\\u6027\\u80FD\\u4F18\\u5316\\u3002\\u8FD9\\u610F\\u5473\\u7740\\uFF0C\\u5982\\u679C\\u60A8\\u8FDE\\u7EED\\u591A\\u6B21\\u8C03\\u7528 \",(0,t.jsx)(e.code,{children:\"setState\"}),\"\\uFF0CReact \\u53EF\\u80FD\\u4F1A\\u5C06\\u5B83\\u4EEC\\u5408\\u5E76\\u4E3A\\u5355\\u4E2A\\u66F4\\u65B0\\u3002\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`this.setState({ count: this.state.count + 1 });\nthis.setState({ count: this.state.count + 1 });\n// React \\u53EF\\u80FD\\u4F1A\\u5C06\\u8FD9\\u4E9B\\u66F4\\u65B0\\u6279\\u5904\\u7406\\u4E3A\\u5355\\u4E2A\\u66F4\\u65B0\n`})}),`\n`,(0,t.jsx)(e.h3,{children:\"\\u56DE\\u8C03\\u51FD\\u6570\"}),`\n`,(0,t.jsxs)(e.p,{children:[\"\\u60A8\\u53EF\\u4EE5\\u5C06\\u56DE\\u8C03\\u51FD\\u6570\\u4F5C\\u4E3A\\u7B2C\\u4E8C\\u4E2A\\u53C2\\u6570\\u4F20\\u9012\\u7ED9 \",(0,t.jsx)(e.code,{children:\"setState\"}),\"\\u3002\\u6B64\\u51FD\\u6570\\u5C06\\u5728\\u72B6\\u6001\\u66F4\\u65B0\\u4E14\\u7EC4\\u4EF6\\u91CD\\u65B0\\u6E32\\u67D3\\u540E\\u88AB\\u8C03\\u7528\\u3002\"]}),`\n`,(0,t.jsx)(e.pre,{children:(0,t.jsx)(e.code,{className:\"language-javascript\",children:`this.setState({ count: this.state.count + 1 }, () => {\n console.log('\\u72B6\\u6001\\u5DF2\\u66F4\\u65B0\\uFF0C\\u7EC4\\u4EF6\\u5DF2\\u91CD\\u65B0\\u6E32\\u67D3');\n});\n`})}),`\n`,(0,t.jsx)(e.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,t.jsxs)(e.ul,{children:[`\n`,(0,t.jsx)(e.li,{children:(0,t.jsx)(e.a,{href:\"https://reactjs.org/docs/react-component.html#setstate\",children:\"React setState \\u6587\\u6863\"})}),`\n`,(0,t.jsx)(e.li,{children:(0,t.jsx)(e.a,{href:\"https://medium.com/@baphemot/understanding-react-setstate-a4640451865b\",children:\"\\u7406\\u89E3 React \\u4E2D\\u7684 setState\"})}),`\n`,(0,t.jsx)(e.li,{children:(0,t.jsx)(e.a,{href:\"https://daveceddia.com/where-fetch-data-componentwillmount-vs-componentdidmount/\",children:\"React \\u7684 setState \\u89E3\\u91CA\"})}),`\n`]})]})}function M(n={}){let{wrapper:e}=n.components||{};return e?(0,t.jsx)(e,Object.assign({},n,{children:(0,t.jsx)(l,n)})):l(n)}var _=M;return f(v);})();\n;return Component;"
+ "solution": "var Component=(()=>{var l=Object.create;var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var C=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),S=(t,e)=>{for(var c in e)a(t,c,{get:e[c],enumerable:!0})},o=(t,e,c,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of p(e))!m.call(t,r)&&r!==c&&a(t,r,{get:()=>e[r],enumerable:!(s=u(e,r))||s.enumerable});return t};var v=(t,e,c)=>(c=t!=null?l(g(t)):{},o(e||!t||!t.__esModule?a(c,\"default\",{value:t,enumerable:!0}):c,t)),f=t=>o(a({},\"__esModule\",{value:!0}),t);var d=C((D,h)=>{h.exports=_jsx_runtime});var _={};S(_,{default:()=>x,frontmatter:()=>R});var n=v(d()),R={title:\"\\u89E3\\u91CA\\u5728 React \\u4E2D\\u8C03\\u7528 `useState` \\u8BBE\\u7F6E\\u5668\\u51FD\\u6570\\u65F6\\u4F1A\\u53D1\\u751F\\u4EC0\\u4E48\"};function i(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",pre:\"pre\",strong:\"strong\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"\\u603B\\u7ED3\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5F53\\u5728 React \\u4E2D\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"useState\"}),\" \\u94A9\\u5B50\\u8FD4\\u56DE\\u7684\\u8BBE\\u7F6E\\u5668\\u51FD\\u6570\\u65F6\\uFF0C\\u5B83\\u4F1A\\u5B89\\u6392\\u5BF9\\u7EC4\\u4EF6\\u72B6\\u6001\\u503C\\u7684\\u66F4\\u65B0\\u3002\\u7136\\u540E\\uFF0CReact \\u4F1A\\u5C06\\u7EC4\\u4EF6\\u91CD\\u65B0\\u6E32\\u67D3\\u4E0E\\u65B0\\u72B6\\u6001\\u6392\\u961F\\u3002\\u6B64\\u8FC7\\u7A0B\\u901A\\u5E38\\u662F\\u5F02\\u6B65\\u7684\\uFF0C\\u5E76\\u4E14 React \\u4F1A\\u5C06\\u591A\\u4E2A\\u72B6\\u6001\\u66F4\\u65B0\\u6279\\u5904\\u7406\\u5728\\u4E00\\u8D77\\u4EE5\\u63D0\\u9AD8\\u6027\\u80FD\\u3002\"]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsxs)(e.h2,{children:[\"\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"useState\"}),\" \\u8BBE\\u7F6E\\u5668\\u65F6\\u4F1A\\u53D1\\u751F\\u4EC0\\u4E48\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u72B6\\u6001\\u66F4\\u65B0\\u8C03\\u5EA6\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5F53\\u60A8\\u8C03\\u7528 \",(0,n.jsx)(e.code,{children:\"useState\"}),\" \\u63D0\\u4F9B\\u7684\\u8BBE\\u7F6E\\u5668\\u51FD\\u6570\\uFF08\\u4F8B\\u5982\\uFF0C\",(0,n.jsx)(e.code,{children:\"setCount\"}),\"\\uFF09\\u65F6\\uFF0CReact \\u4F1A\\u5B89\\u6392\\u5BF9\\u8BE5\\u7279\\u5B9A\\u72B6\\u6001\\u53D8\\u91CF\\u7684\\u66F4\\u65B0\\u3002\\u8FD9\\u4E0D\\u4F1A\\u7ACB\\u5373\\u53D1\\u751F\\uFF1BReact \\u4F1A\\u5C06\\u7EC4\\u4EF6\\u6807\\u8BB0\\u4E3A\\u9700\\u8981\\u4F7F\\u7528\\u66F4\\u65B0\\u540E\\u7684\\u72B6\\u6001\\u503C\\u91CD\\u65B0\\u6E32\\u67D3\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`const [count, setCount] = useState(0);\n// ...\nsetCount(count + 1); // \\u5B89\\u6392\\u66F4\\u65B0\\u4EE5\\u5C06 'count' \\u8BBE\\u7F6E\\u4E3A 1\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u72B6\\u6001\\u66FF\\u6362\"}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"useState\"}),\" \\u8BBE\\u7F6E\\u5668\\u51FD\\u6570\",(0,n.jsx)(e.strong,{children:\"\\u5B8C\\u5168\\u66FF\\u6362\"}),\"\\u60A8\\u63D0\\u4F9B\\u7684\\u65B0\\u503C\\u4E2D\\u7684\\u65E7\\u72B6\\u6001\\u503C\\u3002\\u5982\\u679C\\u60A8\\u7684\\u72B6\\u6001\\u662F\\u4E00\\u4E2A\\u5BF9\\u8C61\\uFF0C\\u5E76\\u4E14\\u60A8\\u53EA\\u60F3\\u66F4\\u65B0\\u4E00\\u4E2A\\u5C5E\\u6027\\uFF0C\\u5219\\u9700\\u8981\\u624B\\u52A8\\u5C55\\u5F00\\u65E7\\u72B6\\u6001\\u5E76\\u8986\\u76D6\\u7279\\u5B9A\\u5C5E\\u6027\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`const [user, setUser] = useState({ name: 'Anon', age: 99 });\n\n// \\u4EC5\\u66F4\\u65B0 name\\uFF0C\\u60A8\\u5FC5\\u987B\\u5C55\\u5F00\\u65E7\\u72B6\\u6001\\uFF1A\nsetUser((prevState) => ({ ...prevState, name: 'John' }));\n// \\u5982\\u679C\\u60A8\\u53EA\\u662F\\u6267\\u884C setUser({ name: 'John' })\\uFF0C\\u5219 'age' \\u5C5E\\u6027\\u5C06\\u4F1A\\u4E22\\u5931\\u3002\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u91CD\\u65B0\\u6E32\\u67D3\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5728\\u5B89\\u6392\\u72B6\\u6001\\u66F4\\u65B0\\u540E\\uFF0CReact \\u6700\\u7EC8\\u5C06\\u89E6\\u53D1\\u7EC4\\u4EF6\\u7684\\u91CD\\u65B0\\u6E32\\u67D3\\u3002\\u51FD\\u6570\\u7EC4\\u4EF6\\u4E3B\\u4F53\\u5C06\\u4F7F\\u7528\\u65B0\\u7684\\u72B6\\u6001\\u503C\\u518D\\u6B21\\u6267\\u884C\\u3002React \\u66F4\\u65B0\\u5176\\u865A\\u62DF DOM\\uFF0C\\u5C06\\u5176\\u4E0E\\u4E4B\\u524D\\u7684\\u7248\\u672C\\u8FDB\\u884C\\u6BD4\\u8F83\\uFF0C\\u5E76\\u4EC5\\u5728\\u5FC5\\u8981\\u65F6\\u6709\\u6548\\u5730\\u66F4\\u65B0\\u5B9E\\u9645 DOM\\u3002\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5F02\\u6B65\\u6027\\u8D28\\u548C\\u6279\\u5904\\u7406\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u7531 \",(0,n.jsx)(e.code,{children:\"useState\"}),\" \\u8BBE\\u7F6E\\u5668\\u89E6\\u53D1\\u7684\\u72B6\\u6001\\u66F4\\u65B0\\u901A\\u5E38\\u662F\\u5F02\\u6B65\\u548C\\u6279\\u5904\\u7406\\u7684\\u3002\\u5982\\u679C\\u60A8\\u5728\\u540C\\u4E00\\u4E2A\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\u6216 effect \\u4E2D\\u8C03\\u7528\\u591A\\u4E2A\\u72B6\\u6001\\u8BBE\\u7F6E\\u5668\\uFF0CReact \\u901A\\u5E38\\u4F1A\\u5C06\\u8FD9\\u4E9B\\u66F4\\u65B0\\u6279\\u5904\\u7406\\u5728\\u4E00\\u8D77\\uFF0C\\u4EE5\\u8FDB\\u884C\\u5355\\u6B21\\u91CD\\u65B0\\u6E32\\u67D3\\uFF0C\\u4ECE\\u800C\\u83B7\\u5F97\\u66F4\\u597D\\u7684\\u6027\\u80FD\\u3002\\u56E0\\u6B64\\uFF0C\\u60A8\\u4E0D\\u5E94\\u8BE5\\u4F9D\\u8D56\\u72B6\\u6001\\u53D8\\u91CF\\u5728\\u8C03\\u7528\\u8BBE\\u7F6E\\u5668\\u540E\\u7ACB\\u5373\\u5177\\u6709\\u65B0\\u503C\\u3002\\u5982\\u679C\\u65B0\\u72B6\\u6001\\u4F9D\\u8D56\\u4E8E\\u4E4B\\u524D\\u7684\\u72B6\\u6001\\uFF0C\\u8BF7\\u4F7F\\u7528\\u51FD\\u6570\\u5F0F\\u66F4\\u65B0\\u5F62\\u5F0F\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`// \\u5047\\u8BBE count \\u4E3A 0\nsetCount(count + 1); // \\u5C06\\u66F4\\u65B0\\u6392\\u961F\\u5230 1\nsetCount(count + 1); // \\u4ECD\\u7136\\u5C06 count \\u89C6\\u4E3A 0\\uFF0C\\u518D\\u6B21\\u5C06\\u66F4\\u65B0\\u6392\\u961F\\u5230 1!\n// \\u7ED3\\u679C\\u53EF\\u80FD\\u662F 1\\uFF0C\\u800C\\u4E0D\\u662F 2\n\n// \\u4F7F\\u7528\\u51FD\\u6570\\u5F0F\\u66F4\\u65B0\\u7684\\u6B63\\u786E\\u65B9\\u6CD5\\uFF1A\nsetCount((prevCount) => prevCount + 1); // \\u6839\\u636E\\u4E4B\\u524D\\u7684\\u72B6\\u6001\\u5C06\\u66F4\\u65B0\\u6392\\u961F\nsetCount((prevCount) => prevCount + 1); // \\u6839\\u636E\\u7B2C\\u4E00\\u4E2A\\u7684\\u7ED3\\u679C\\u5C06\\u53E6\\u4E00\\u4E2A\\u66F4\\u65B0\\u6392\\u961F\n// \\u7ED3\\u679C\\u5C06\\u662F 2\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsxs)(e.a,{href:\"https://react.dev/reference/react/useState\",children:[\"React \\u6587\\u6863\\uFF1A\\u4F7F\\u7528\\u72B6\\u6001 Hook (\",(0,n.jsx)(e.code,{children:\"useState\"}),\")\"]})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/reference/react/useState#updating-state-based-on-the-previous-state\",children:\"React \\u6587\\u6863\\uFF1A\\u5C06\\u591A\\u4E2A\\u72B6\\u6001\\u66F4\\u65B0\\u6392\\u961F\"})}),`\n`]})]})}function j(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(i,t)})):i(t)}var x=j;return f(_);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-what-react-hydration-is/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/explain-what-react-hydration-is/locales/en-US.json
index 0896465a7..92d8357b2 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-what-react-hydration-is/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-what-react-hydration-is/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "Explain what React hydration is",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-what-react-hydration-is/en-US.mdx"
},
- "solution": "var Component=(()=>{var o=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var u=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),y=(t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:!0})},c=(t,e,i,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of p(e))!v.call(t,r)&&r!==i&&a(t,r,{get:()=>e[r],enumerable:!(s=g(e,r))||s.enumerable});return t};var f=(t,e,i)=>(i=t!=null?o(m(t)):{},c(e||!t||!t.__esModule?a(i,\"default\",{value:t,enumerable:!0}):i,t)),R=t=>c(a({},\"__esModule\",{value:!0}),t);var l=u((L,h)=>{h.exports=_jsx_runtime});var T={};y(T,{default:()=>x,frontmatter:()=>b});var n=f(l()),b={title:\"Explain what React hydration is\"};function d(t){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",pre:\"pre\",code:\"code\",ul:\"ul\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"React hydration is the process of attaching event listeners and making a server-rendered HTML page interactive on the client side. When a React application is server-side rendered, the HTML is sent to the client, and React takes over to make it dynamic by attaching event handlers and initializing state. This process is called hydration.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"What is React hydration?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Server-side rendering (SSR)\"}),`\n`,(0,n.jsx)(e.p,{children:\"Server-side rendering (SSR) is a technique where the HTML of a web page is generated on the server and sent to the client. This allows for faster initial page loads and better SEO since the content is already available when the page is loaded.\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Hydration process\"}),`\n`,(0,n.jsx)(e.p,{children:'Hydration is the process that happens after the server-side rendered HTML is sent to the client. React takes the static HTML and \"hydrates\" it by attaching event listeners and initializing the state, making the page interactive. This process involves:'}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Reusing the existing HTML\"}),\": React uses the HTML generated by the server and does not re-render it from scratch.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Attaching event listeners\"}),\": React attaches the necessary event listeners to the existing HTML elements.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Initializing state\"}),\": React initializes the component state and props to make the page dynamic.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Example\"}),`\n`,(0,n.jsx)(e.p,{children:\"Here's a simple example to illustrate the concept:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"Server-side rendering\"}),\": The server generates the following HTML:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-html\",children:`\n Click me \n
\n`})}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"Client-side hydration\"}),\": When the HTML is sent to the client, React hydrates it with the following code:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`import React from 'react';\nimport ReactDOM from 'react-dom';\n\nfunction App() {\n const handleClick = () => {\n alert('Button clicked!');\n };\n\n return Click me ;\n}\n\nReactDOM.hydrate( , document.getElementById('root'));\n`})}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"In this example, the server sends the static HTML with a button to the client. React then hydrates the button by attaching the \",(0,n.jsx)(e.code,{children:\"onClick\"}),\" event listener, making it interactive.\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Benefits of hydration\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Faster initial load\"}),\": Since the HTML is already available, the initial page load is faster.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"SEO benefits\"}),\": Search engines can crawl the server-rendered HTML, improving SEO.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Improved user experience\"}),\": Users can see the content immediately, even before React has fully taken over.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Challenges of hydration\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Mismatch issues\"}),\": If the server-rendered HTML does not match the client-side React components, it can cause errors and warnings.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Performance overhead\"}),\": Hydration can be resource-intensive, especially for large applications.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/react-dom.html#hydrate\",children:\"React documentation on hydration\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/react-dom-server.html\",children:\"Server-side rendering in React\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://nextjs.org/docs/basic-features/pages#hydration\",children:\"Next.js documentation on hydration\"})}),`\n`]})]})}function M(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(d,t)})):d(t)}var x=M;return R(T);})();\n;return Component;"
+ "solution": "var Component=(()=>{var o=Object.create;var a=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var u=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),f=(t,e)=>{for(var i in e)a(t,i,{get:e[i],enumerable:!0})},s=(t,e,i,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of p(e))!v.call(t,r)&&r!==i&&a(t,r,{get:()=>e[r],enumerable:!(c=g(e,r))||c.enumerable});return t};var y=(t,e,i)=>(i=t!=null?o(m(t)):{},s(e||!t||!t.__esModule?a(i,\"default\",{value:t,enumerable:!0}):i,t)),R=t=>s(a({},\"__esModule\",{value:!0}),t);var l=u((L,h)=>{h.exports=_jsx_runtime});var T={};f(T,{default:()=>x,frontmatter:()=>b});var n=y(l()),b={title:\"Explain what React hydration is\"};function d(t){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",pre:\"pre\",code:\"code\",ul:\"ul\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"React hydration is the process of attaching event listeners and making a server-rendered HTML page interactive on the client side. When a React application is server-side rendered, the HTML is sent to the client, and React takes over to make it dynamic by attaching event handlers and initializing state. This process is called hydration.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"What is React hydration?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Server-side rendering (SSR)\"}),`\n`,(0,n.jsx)(e.p,{children:\"Server-side rendering (SSR) is a technique where the HTML of a web page is generated on the server and sent to the client. This allows for faster initial page loads and better SEO since the content is already available when the page is loaded.\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Hydration process\"}),`\n`,(0,n.jsx)(e.p,{children:'Hydration is the process that happens after the server-side rendered HTML is sent to the client. React takes the static HTML and \"hydrates\" it by attaching event listeners and initializing the state, making the page interactive. This process involves:'}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Reusing the existing HTML\"}),\": React uses the HTML generated by the server and does not re-render it from scratch.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Attaching event listeners\"}),\": React attaches the necessary event listeners to the existing HTML elements.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Initializing state\"}),\": React initializes the component state and props to make the page dynamic.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Example\"}),`\n`,(0,n.jsx)(e.p,{children:\"Here's a simple example to illustrate the concept:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"Server-side rendering\"}),\": The server generates the following HTML:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-html\",children:`\n Click me \n
\n`})}),`\n`]}),`\n`,(0,n.jsxs)(e.li,{children:[`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.strong,{children:\"Client-side hydration\"}),\": When the HTML is sent to the client, React hydrates it with the following code:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`import React from 'react';\nimport ReactDOM from 'react-dom';\n\nfunction App() {\n const handleClick = () => {\n alert('Button clicked!');\n };\n\n return Click me ;\n}\n\nReactDOM.hydrate( , document.getElementById('root'));\n`})}),`\n`]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"In this example, the server sends the static HTML with a button to the client. React then hydrates the button by attaching the \",(0,n.jsx)(e.code,{children:\"onClick\"}),\" event listener, making it interactive.\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Benefits of hydration\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Faster initial load\"}),\": Since the HTML is already available, the initial page load is faster.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"SEO benefits\"}),\": Search engines can crawl the server-rendered HTML, improving SEO.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Improved user experience\"}),\": Users can see the content immediately, even before React has fully taken over.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Challenges of hydration\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Mismatch issues\"}),\": If the server-rendered HTML does not match the client-side React components, it can cause errors and warnings.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Performance overhead\"}),\": Hydration can be resource-intensive, especially for large applications.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/reference/react-dom/client/hydrateRoot\",children:\"React documentation on hydration\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/reference/react-dom/server\",children:\"Server-side rendering in React\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://nextjs.org/docs/basic-features/pages#hydration\",children:\"Next.js documentation on hydration\"})}),`\n`]})]})}function M(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(d,t)})):d(t)}var x=M;return R(T);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/explain-what-react-hydration-is/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/explain-what-react-hydration-is/locales/zh-CN.json
index 04aa96e38..46974d06e 100644
--- a/apps/web/src/__generated__/questions/quiz/explain-what-react-hydration-is/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/explain-what-react-hydration-is/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "解释 React 水合是什么",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/explain-what-react-hydration-is/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var R=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),M=(r,n)=>{for(var c in n)l(r,c,{get:n[c],enumerable:!0})},h=(r,n,c,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of g(n))!u.call(r,t)&&t!==c&&l(r,t,{get:()=>n[t],enumerable:!(i=p(n,t))||i.enumerable});return r};var L=(r,n,c)=>(c=r!=null?s(m(r)):{},h(n||!r||!r.__esModule?l(c,\"default\",{value:r,enumerable:!0}):c,r)),T=r=>h(l({},\"__esModule\",{value:!0}),r);var o=R((b,d)=>{d.exports=_jsx_runtime});var x={};M(x,{default:()=>j,frontmatter:()=>H});var e=L(o()),H={title:\"\\u89E3\\u91CA React \\u6C34\\u5408\\u662F\\u4EC0\\u4E48\"};function a(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",pre:\"pre\",code:\"code\",ul:\"ul\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u6C34\\u5408\\u662F\\u5728\\u5BA2\\u6237\\u7AEF\\u9644\\u52A0\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u5E76\\u4F7F\\u670D\\u52A1\\u5668\\u6E32\\u67D3\\u7684 HTML \\u9875\\u9762\\u5177\\u6709\\u4EA4\\u4E92\\u6027\\u7684\\u8FC7\\u7A0B\\u3002\\u5F53 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u8FDB\\u884C\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u65F6\\uFF0CHTML \\u4F1A\\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\uFF0CReact \\u4F1A\\u63A5\\u7BA1\\u5E76\\u901A\\u8FC7\\u9644\\u52A0\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\u548C\\u521D\\u59CB\\u5316\\u72B6\\u6001\\u6765\\u4F7F\\u5176\\u5177\\u6709\\u52A8\\u6001\\u6027\\u3002\\u6B64\\u8FC7\\u7A0B\\u79F0\\u4E3A\\u6C34\\u5408\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4EC0\\u4E48\\u662F React \\u6C34\\u5408\\uFF1F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3 (SSR)\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3 (SSR) \\u662F\\u4E00\\u79CD\\u5728\\u670D\\u52A1\\u5668\\u4E0A\\u751F\\u6210\\u7F51\\u9875 HTML \\u5E76\\u5C06\\u5176\\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u7684\\u6280\\u672F\\u3002\\u8FD9\\u5141\\u8BB8\\u66F4\\u5FEB\\u7684\\u521D\\u59CB\\u9875\\u9762\\u52A0\\u8F7D\\u548C\\u66F4\\u597D\\u7684 SEO\\uFF0C\\u56E0\\u4E3A\\u5185\\u5BB9\\u5728\\u52A0\\u8F7D\\u9875\\u9762\\u65F6\\u5DF2\\u7ECF\\u53EF\\u7528\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6C34\\u5408\\u8FC7\\u7A0B\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6C34\\u5408\\u662F\\u5728\\u5C06\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u7684 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u540E\\u53D1\\u751F\\u7684\\u8FC7\\u7A0B\\u3002React \\u83B7\\u53D6\\u9759\\u6001 HTML \\u5E76\\u901A\\u8FC7\\u9644\\u52A0\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u548C\\u521D\\u59CB\\u5316\\u72B6\\u6001\\u6765\\u201C\\u6C34\\u5408\\u201D\\u5B83\\uFF0C\\u4ECE\\u800C\\u4F7F\\u9875\\u9762\\u5177\\u6709\\u4EA4\\u4E92\\u6027\\u3002\\u6B64\\u8FC7\\u7A0B\\u6D89\\u53CA\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u91CD\\u7528\\u73B0\\u6709\\u7684 HTML\"}),\"\\uFF1AReact \\u4F7F\\u7528\\u670D\\u52A1\\u5668\\u751F\\u6210\\u7684 HTML\\uFF0C\\u800C\\u4E0D\\u662F\\u4ECE\\u5934\\u5F00\\u59CB\\u91CD\\u65B0\\u6E32\\u67D3\\u5B83\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u9644\\u52A0\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\"}),\"\\uFF1AReact \\u5C06\\u5FC5\\u8981\\u7684\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u9644\\u52A0\\u5230\\u73B0\\u6709\\u7684 HTML \\u5143\\u7D20\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u521D\\u59CB\\u5316\\u72B6\\u6001\"}),\"\\uFF1AReact \\u521D\\u59CB\\u5316\\u7EC4\\u4EF6\\u72B6\\u6001\\u548C\\u5C5E\\u6027\\u4EE5\\u4F7F\\u9875\\u9762\\u5177\\u6709\\u52A8\\u6001\\u6027\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u662F\\u4E00\\u4E2A\\u7B80\\u5355\\u7684\\u4F8B\\u5B50\\uFF0C\\u8BF4\\u660E\\u8FD9\\u4E2A\\u6982\\u5FF5\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.strong,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\"}),\"\\uFF1A\\u670D\\u52A1\\u5668\\u751F\\u6210\\u4EE5\\u4E0B HTML\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-html\",children:`\n Click me \n
\n`})}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.strong,{children:\"\\u5BA2\\u6237\\u7AEF\\u6C34\\u5408\"}),\"\\uFF1A\\u5F53 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u65F6\\uFF0CReact \\u4F7F\\u7528\\u4EE5\\u4E0B\\u4EE3\\u7801\\u5BF9\\u5176\\u8FDB\\u884C\\u6C34\\u5408\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React from 'react';\nimport ReactDOM from 'react-dom';\n\nfunction App() {\n const handleClick = () => {\n alert('Button clicked!');\n };\n\n return Click me ;\n}\n\nReactDOM.hydrate( , document.getElementById('root'));\n`})}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u6B64\\u793A\\u4F8B\\u4E2D\\uFF0C\\u670D\\u52A1\\u5668\\u5C06\\u5E26\\u6709\\u6309\\u94AE\\u7684\\u9759\\u6001 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u3002\\u7136\\u540E\\uFF0CReact \\u901A\\u8FC7\\u9644\\u52A0 \",(0,e.jsx)(n.code,{children:\"onClick\"}),\" \\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u6765\\u5BF9\\u6309\\u94AE\\u8FDB\\u884C\\u6C34\\u5408\\uFF0C\\u4F7F\\u5176\\u5177\\u6709\\u4EA4\\u4E92\\u6027\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6C34\\u5408\\u7684\\u597D\\u5904\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u66F4\\u5FEB\\u7684\\u521D\\u59CB\\u52A0\\u8F7D\"}),\"\\uFF1A\\u7531\\u4E8E HTML \\u5DF2\\u7ECF\\u53EF\\u7528\\uFF0C\\u56E0\\u6B64\\u521D\\u59CB\\u9875\\u9762\\u52A0\\u8F7D\\u901F\\u5EA6\\u66F4\\u5FEB\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"SEO \\u4F18\\u52BF\"}),\"\\uFF1A\\u641C\\u7D22\\u5F15\\u64CE\\u53EF\\u4EE5\\u6293\\u53D6\\u670D\\u52A1\\u5668\\u6E32\\u67D3\\u7684 HTML\\uFF0C\\u4ECE\\u800C\\u6539\\u5584 SEO\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6539\\u8FDB\\u7684\\u7528\\u6237\\u4F53\\u9A8C\"}),\"\\uFF1A\\u7528\\u6237\\u53EF\\u4EE5\\u7ACB\\u5373\\u770B\\u5230\\u5185\\u5BB9\\uFF0C\\u751A\\u81F3\\u5728 React \\u5B8C\\u5168\\u63A5\\u7BA1\\u4E4B\\u524D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6C34\\u5408\\u7684\\u6311\\u6218\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E0D\\u5339\\u914D\\u95EE\\u9898\"}),\"\\uFF1A\\u5982\\u679C\\u670D\\u52A1\\u5668\\u6E32\\u67D3\\u7684 HTML \\u4E0E\\u5BA2\\u6237\\u7AEF React \\u7EC4\\u4EF6\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u53EF\\u80FD\\u5BFC\\u81F4\\u9519\\u8BEF\\u548C\\u8B66\\u544A\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6027\\u80FD\\u5F00\\u9500\"}),\"\\uFF1A\\u6C34\\u5408\\u53EF\\u80FD\\u5360\\u7528\\u5927\\u91CF\\u8D44\\u6E90\\uFF0C\\u5C24\\u5176\\u5BF9\\u4E8E\\u5927\\u578B\\u5E94\\u7528\\u7A0B\\u5E8F\\u800C\\u8A00\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/react-dom.html#hydrate\",children:\"React \\u6C34\\u5408\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/react-dom-server.html\",children:\"React \\u4E2D\\u7684\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nextjs.org/docs/basic-features/pages#hydration\",children:\"Next.js \\u6C34\\u5408\\u6587\\u6863\"})}),`\n`]})]})}function f(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(a,r)})):a(r)}var j=f;return T(x);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,R=Object.prototype.hasOwnProperty;var u=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),M=(r,n)=>{for(var c in n)l(r,c,{get:n[c],enumerable:!0})},h=(r,n,c,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let t of g(n))!R.call(r,t)&&t!==c&&l(r,t,{get:()=>n[t],enumerable:!(i=p(n,t))||i.enumerable});return r};var L=(r,n,c)=>(c=r!=null?s(m(r)):{},h(n||!r||!r.__esModule?l(c,\"default\",{value:r,enumerable:!0}):c,r)),T=r=>h(l({},\"__esModule\",{value:!0}),r);var o=u((b,d)=>{d.exports=_jsx_runtime});var j={};M(j,{default:()=>x,frontmatter:()=>f});var e=L(o()),f={title:\"\\u89E3\\u91CA React \\u6C34\\u5408\\u662F\\u4EC0\\u4E48\"};function a(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",pre:\"pre\",code:\"code\",ul:\"ul\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u6C34\\u5408\\u662F\\u5728\\u5BA2\\u6237\\u7AEF\\u9644\\u52A0\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u5E76\\u4F7F\\u670D\\u52A1\\u5668\\u6E32\\u67D3\\u7684 HTML \\u9875\\u9762\\u5177\\u6709\\u4EA4\\u4E92\\u6027\\u7684\\u8FC7\\u7A0B\\u3002\\u5F53 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u8FDB\\u884C\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u65F6\\uFF0CHTML \\u4F1A\\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\uFF0CReact \\u4F1A\\u63A5\\u7BA1\\u5E76\\u901A\\u8FC7\\u9644\\u52A0\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\u548C\\u521D\\u59CB\\u5316\\u72B6\\u6001\\u6765\\u4F7F\\u5176\\u5177\\u6709\\u52A8\\u6001\\u6027\\u3002\\u6B64\\u8FC7\\u7A0B\\u79F0\\u4E3A\\u6C34\\u5408\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4EC0\\u4E48\\u662F React \\u6C34\\u5408\\uFF1F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3 (SSR)\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3 (SSR) \\u662F\\u4E00\\u79CD\\u5728\\u670D\\u52A1\\u5668\\u4E0A\\u751F\\u6210\\u7F51\\u9875 HTML \\u5E76\\u5C06\\u5176\\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u7684\\u6280\\u672F\\u3002\\u8FD9\\u5141\\u8BB8\\u66F4\\u5FEB\\u7684\\u521D\\u59CB\\u9875\\u9762\\u52A0\\u8F7D\\u548C\\u66F4\\u597D\\u7684 SEO\\uFF0C\\u56E0\\u4E3A\\u5185\\u5BB9\\u5728\\u52A0\\u8F7D\\u9875\\u9762\\u65F6\\u5DF2\\u7ECF\\u53EF\\u7528\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6C34\\u5408\\u8FC7\\u7A0B\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6C34\\u5408\\u662F\\u5728\\u5C06\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\\u7684 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u540E\\u53D1\\u751F\\u7684\\u8FC7\\u7A0B\\u3002React \\u83B7\\u53D6\\u9759\\u6001 HTML \\u5E76\\u901A\\u8FC7\\u9644\\u52A0\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u548C\\u521D\\u59CB\\u5316\\u72B6\\u6001\\u6765\\u201C\\u6C34\\u5408\\u201D\\u5B83\\uFF0C\\u4ECE\\u800C\\u4F7F\\u9875\\u9762\\u5177\\u6709\\u4EA4\\u4E92\\u6027\\u3002\\u6B64\\u8FC7\\u7A0B\\u6D89\\u53CA\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u91CD\\u7528\\u73B0\\u6709\\u7684 HTML\"}),\"\\uFF1AReact \\u4F7F\\u7528\\u670D\\u52A1\\u5668\\u751F\\u6210\\u7684 HTML\\uFF0C\\u800C\\u4E0D\\u662F\\u4ECE\\u5934\\u5F00\\u59CB\\u91CD\\u65B0\\u6E32\\u67D3\\u5B83\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u9644\\u52A0\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\"}),\"\\uFF1AReact \\u5C06\\u5FC5\\u8981\\u7684\\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u9644\\u52A0\\u5230\\u73B0\\u6709\\u7684 HTML \\u5143\\u7D20\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u521D\\u59CB\\u5316\\u72B6\\u6001\"}),\"\\uFF1AReact \\u521D\\u59CB\\u5316\\u7EC4\\u4EF6\\u72B6\\u6001\\u548C\\u5C5E\\u6027\\u4EE5\\u4F7F\\u9875\\u9762\\u5177\\u6709\\u52A8\\u6001\\u6027\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u662F\\u4E00\\u4E2A\\u7B80\\u5355\\u7684\\u4F8B\\u5B50\\uFF0C\\u8BF4\\u660E\\u8FD9\\u4E2A\\u6982\\u5FF5\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.strong,{children:\"\\u670D\\u52A1\\u5668\\u7AEF\\u6E32\\u67D3\"}),\"\\uFF1A\\u670D\\u52A1\\u5668\\u751F\\u6210\\u4EE5\\u4E0B HTML\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-html\",children:`\n Click me \n
\n`})}),`\n`]}),`\n`,(0,e.jsxs)(n.li,{children:[`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.strong,{children:\"\\u5BA2\\u6237\\u7AEF\\u6C34\\u5408\"}),\"\\uFF1A\\u5F53 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u65F6\\uFF0CReact \\u4F7F\\u7528\\u4EE5\\u4E0B\\u4EE3\\u7801\\u5BF9\\u5176\\u8FDB\\u884C\\u6C34\\u5408\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React from 'react';\nimport ReactDOM from 'react-dom';\n\nfunction App() {\n const handleClick = () => {\n alert('Button clicked!');\n };\n\n return Click me ;\n}\n\nReactDOM.hydrate( , document.getElementById('root'));\n`})}),`\n`]}),`\n`]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u6B64\\u793A\\u4F8B\\u4E2D\\uFF0C\\u670D\\u52A1\\u5668\\u5C06\\u5E26\\u6709\\u6309\\u94AE\\u7684\\u9759\\u6001 HTML \\u53D1\\u9001\\u5230\\u5BA2\\u6237\\u7AEF\\u3002\\u7136\\u540E\\uFF0CReact \\u901A\\u8FC7\\u9644\\u52A0 \",(0,e.jsx)(n.code,{children:\"onClick\"}),\" \\u4E8B\\u4EF6\\u76D1\\u542C\\u5668\\u6765\\u5BF9\\u6309\\u94AE\\u8FDB\\u884C\\u6C34\\u5408\\uFF0C\\u4F7F\\u5176\\u5177\\u6709\\u4EA4\\u4E92\\u6027\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6C34\\u5408\\u7684\\u597D\\u5904\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u66F4\\u5FEB\\u7684\\u521D\\u59CB\\u52A0\\u8F7D\"}),\"\\uFF1A\\u7531\\u4E8E HTML \\u5DF2\\u7ECF\\u53EF\\u7528\\uFF0C\\u56E0\\u6B64\\u521D\\u59CB\\u9875\\u9762\\u52A0\\u8F7D\\u901F\\u5EA6\\u66F4\\u5FEB\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"SEO \\u4F18\\u52BF\"}),\"\\uFF1A\\u641C\\u7D22\\u5F15\\u64CE\\u53EF\\u4EE5\\u6293\\u53D6\\u670D\\u52A1\\u5668\\u6E32\\u67D3\\u7684 HTML\\uFF0C\\u4ECE\\u800C\\u6539\\u5584 SEO\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6539\\u8FDB\\u7684\\u7528\\u6237\\u4F53\\u9A8C\"}),\"\\uFF1A\\u7528\\u6237\\u53EF\\u4EE5\\u7ACB\\u5373\\u770B\\u5230\\u5185\\u5BB9\\uFF0C\\u751A\\u81F3\\u5728 React \\u5B8C\\u5168\\u63A5\\u7BA1\\u4E4B\\u524D\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6C34\\u5408\\u7684\\u6311\\u6218\"}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E0D\\u5339\\u914D\\u95EE\\u9898\"}),\"\\uFF1A\\u5982\\u679C\\u670D\\u52A1\\u5668\\u6E32\\u67D3\\u7684 HTML \\u4E0E\\u5BA2\\u6237\\u7AEF React \\u7EC4\\u4EF6\\u4E0D\\u5339\\u914D\\uFF0C\\u5219\\u53EF\\u80FD\\u5BFC\\u81F4\\u9519\\u8BEF\\u548C\\u8B66\\u544A\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6027\\u80FD\\u5F00\\u9500\"}),\"\\uFF1A\\u6C34\\u5408\\u53EF\\u80FD\\u5360\\u7528\\u5927\\u91CF\\u8D44\\u6E90\\uFF0C\\u5C24\\u5176\\u5BF9\\u4E8E\\u5927\\u578B\\u5E94\\u7528\\u7A0B\\u5E8F\\u800C\\u8A00\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/reference/react-dom/client/hydrateRoot\",children:\"React \\u6587\\u6863\\u5173\\u4E8E hydration\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/reference/react-dom/server\",children:\"React \\u4E2D\\u7684\\u670D\\u52A1\\u7AEF\\u6E32\\u67D3\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://nextjs.org/docs/basic-features/pages#hydration\",children:\"Next.js \\u6587\\u6863\\u5173\\u4E8E hydration\"})}),`\n`]})]})}function H(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(a,r)})):a(r)}var x=H;return T(j);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-can-you-optimize-dom-manipulation-for-better-performance/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-can-you-optimize-dom-manipulation-for-better-performance/locales/en-US.json
index 20d6b930d..559a0df38 100644
--- a/apps/web/src/__generated__/questions/quiz/how-can-you-optimize-dom-manipulation-for-better-performance/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-can-you-optimize-dom-manipulation-for-better-performance/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How can you optimize DOM manipulation for better performance?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-can-you-optimize-dom-manipulation-for-better-performance/en-US.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var o=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var y=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),f=(t,e)=>{for(var i in e)o(t,i,{get:e[i],enumerable:!0})},l=(t,e,i,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of u(e))!g.call(t,r)&&r!==i&&o(t,r,{get:()=>e[r],enumerable:!(a=h(e,r))||a.enumerable});return t};var b=(t,e,i)=>(i=t!=null?s(p(t)):{},l(e||!t||!t.__esModule?o(i,\"default\",{value:t,enumerable:!0}):i,t)),w=t=>l(o({},\"__esModule\",{value:!0}),t);var d=y((x,c)=>{c.exports=_jsx_runtime});var E={};f(E,{default:()=>M,frontmatter:()=>D});var n=b(d()),D={title:\"How can you optimize DOM manipulation for better performance?\"};function m(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",pre:\"pre\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"To optimize DOM manipulation for better performance, minimize direct DOM access and updates. Use techniques like batching DOM changes, using \",(0,n.jsx)(e.code,{children:\"documentFragment\"}),\" for multiple elements, and leveraging virtual DOM libraries like React. Also, consider using \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" for animations and avoid layout thrashing by reading and writing DOM properties separately.\"]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"How can you optimize DOM manipulation for better performance?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Minimize direct DOM access\"}),`\n`,(0,n.jsx)(e.p,{children:\"Accessing the DOM is relatively slow, so try to minimize the number of times you read from or write to the DOM. Instead, store references to elements in variables and work with those.\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement'); // Access once\n// Then use the reference to edit style\nelement.style.color = 'red';\nelement.style.backgroundColor = 'blue';\n\nconsole.log(document.body); // Notice the edits\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Batch DOM changes\"}),`\n`,(0,n.jsx)(e.p,{children:\"Instead of making multiple changes to the DOM one at a time, batch them together. This reduces the number of reflows and repaints.\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement');\nelement.style.cssText = 'color: red; background-color: blue;';\n\nconsole.log(document.body); // Notice the edits\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Use \",(0,n.jsx)(e.code,{children:\"documentFragment\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"When adding multiple elements to the DOM, use a \",(0,n.jsx)(e.code,{children:\"documentFragment\"}),\" to minimize reflows and repaints.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const fragment = document.createDocumentFragment();\nfor (let i = 0; i < 100; i++) {\n const newElement = document.createElement('div');\n newElement.textContent = \\`Item \\${i}\\`;\n fragment.appendChild(newElement);\n}\ndocument.body.appendChild(fragment);\n\nconsole.log(document.body); // Notice that the divs have been added\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Leverage virtual DOM libraries\"}),`\n`,(0,n.jsx)(e.p,{children:\"Libraries like React use a virtual DOM to batch updates and minimize direct DOM manipulation, which can significantly improve performance.\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`import React from 'react';\nimport ReactDOM from 'react-dom';\n\nconst App = () => (\n \n
Hello, world! \n \n);\n\nReactDOM.render( , document.getElementById('root'));\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Use \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" for animations\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"For smoother animations, use \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" to ensure updates are synchronized with the browser's repaint cycle.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`function animate() {\n // Update animation state\n requestAnimationFrame(animate);\n}\nrequestAnimationFrame(animate);\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Avoid layout thrashing\"}),`\n`,(0,n.jsx)(e.p,{children:\"Layout thrashing occurs when you read and write to the DOM repeatedly in a way that forces the browser to recalculate styles and layout multiple times. To avoid this, separate read and write operations.\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement');\nconst height = element.clientHeight; // Read\nelement.style.height = \\`\\${height + 10}px\\`; // Write\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Manipulating_the_DOM\",children:\"MDN Web Docs: DOM manipulation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing\",children:\"Google Developers: Avoid large, complex layouts and layout thrashing\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/getting-started.html\",children:\"React documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame\",children:\"MDN Web Docs: Using requestAnimationFrame\"})}),`\n`]})]})}function v(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(m,t)})):m(t)}var M=v;return w(E);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var o=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var y=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),f=(t,e)=>{for(var i in e)o(t,i,{get:e[i],enumerable:!0})},l=(t,e,i,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of u(e))!g.call(t,r)&&r!==i&&o(t,r,{get:()=>e[r],enumerable:!(a=h(e,r))||a.enumerable});return t};var b=(t,e,i)=>(i=t!=null?s(p(t)):{},l(e||!t||!t.__esModule?o(i,\"default\",{value:t,enumerable:!0}):i,t)),w=t=>l(o({},\"__esModule\",{value:!0}),t);var d=y((x,c)=>{c.exports=_jsx_runtime});var E={};f(E,{default:()=>M,frontmatter:()=>D});var n=b(d()),D={title:\"How can you optimize DOM manipulation for better performance?\"};function m(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",pre:\"pre\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"To optimize DOM manipulation for better performance, minimize direct DOM access and updates. Use techniques like batching DOM changes, using \",(0,n.jsx)(e.code,{children:\"documentFragment\"}),\" for multiple elements, and leveraging virtual DOM libraries like React. Also, consider using \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" for animations and avoid layout thrashing by reading and writing DOM properties separately.\"]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"How can you optimize DOM manipulation for better performance?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Minimize direct DOM access\"}),`\n`,(0,n.jsx)(e.p,{children:\"Accessing the DOM is relatively slow, so try to minimize the number of times you read from or write to the DOM. Instead, store references to elements in variables and work with those.\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement'); // Access once\n// Then use the reference to edit style\nelement.style.color = 'red';\nelement.style.backgroundColor = 'blue';\n\nconsole.log(document.body); // Notice the edits\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Batch DOM changes\"}),`\n`,(0,n.jsx)(e.p,{children:\"Instead of making multiple changes to the DOM one at a time, batch them together. This reduces the number of reflows and repaints.\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement');\nelement.style.cssText = 'color: red; background-color: blue;';\n\nconsole.log(document.body); // Notice the edits\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Use \",(0,n.jsx)(e.code,{children:\"documentFragment\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"When adding multiple elements to the DOM, use a \",(0,n.jsx)(e.code,{children:\"documentFragment\"}),\" to minimize reflows and repaints.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const fragment = document.createDocumentFragment();\nfor (let i = 0; i < 100; i++) {\n const newElement = document.createElement('div');\n newElement.textContent = \\`Item \\${i}\\`;\n fragment.appendChild(newElement);\n}\ndocument.body.appendChild(fragment);\n\nconsole.log(document.body); // Notice that the divs have been added\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Leverage virtual DOM libraries\"}),`\n`,(0,n.jsx)(e.p,{children:\"Libraries like React use a virtual DOM to batch updates and minimize direct DOM manipulation, which can significantly improve performance.\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`import React from 'react';\nimport ReactDOM from 'react-dom';\n\nconst App = () => (\n \n
Hello, world! \n \n);\n\nReactDOM.render( , document.getElementById('root'));\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Use \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" for animations\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"For smoother animations, use \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" to ensure updates are synchronized with the browser's repaint cycle.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`function animate() {\n // Update animation state\n requestAnimationFrame(animate);\n}\nrequestAnimationFrame(animate);\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Avoid layout thrashing\"}),`\n`,(0,n.jsx)(e.p,{children:\"Layout thrashing occurs when you read and write to the DOM repeatedly in a way that forces the browser to recalculate styles and layout multiple times. To avoid this, separate read and write operations.\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement');\nconst height = element.clientHeight; // Read\nelement.style.height = \\`\\${height + 10}px\\`; // Write\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Manipulating_the_DOM\",children:\"MDN Web Docs: DOM manipulation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing\",children:\"Google Developers: Avoid large, complex layouts and layout thrashing\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn\",children:\"React documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame\",children:\"MDN Web Docs: Using requestAnimationFrame\"})}),`\n`]})]})}function v(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(m,t)})):m(t)}var M=v;return w(E);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-can-you-optimize-dom-manipulation-for-better-performance/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/how-can-you-optimize-dom-manipulation-for-better-performance/locales/zh-CN.json
index 663887554..fb53de536 100644
--- a/apps/web/src/__generated__/questions/quiz/how-can-you-optimize-dom-manipulation-for-better-performance/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/how-can-you-optimize-dom-manipulation-for-better-performance/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "如何优化 DOM 操作以获得更好的性能?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-can-you-optimize-dom-manipulation-for-better-performance/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var r=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var D=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),E=(t,e)=>{for(var l in e)r(t,l,{get:e[l],enumerable:!0})},d=(t,e,l,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of u(e))!g.call(t,c)&&c!==l&&r(t,c,{get:()=>e[c],enumerable:!(o=s(e,c))||o.enumerable});return t};var M=(t,e,l)=>(l=t!=null?h(p(t)):{},d(e||!t||!t.__esModule?r(l,\"default\",{value:t,enumerable:!0}):l,t)),y=t=>d(r({},\"__esModule\",{value:!0}),t);var i=D((j,m)=>{m.exports=_jsx_runtime});var f={};E(f,{default:()=>w,frontmatter:()=>O});var n=M(i()),O={title:\"\\u5982\\u4F55\\u4F18\\u5316 DOM \\u64CD\\u4F5C\\u4EE5\\u83B7\\u5F97\\u66F4\\u597D\\u7684\\u6027\\u80FD\\uFF1F\"};function a(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",pre:\"pre\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8981\\u4F18\\u5316 DOM \\u64CD\\u4F5C\\u4EE5\\u83B7\\u5F97\\u66F4\\u597D\\u7684\\u6027\\u80FD\\uFF0C\\u8BF7\\u5C3D\\u91CF\\u51CF\\u5C11\\u76F4\\u63A5\\u8BBF\\u95EE\\u548C\\u66F4\\u65B0 DOM\\u3002\\u4F7F\\u7528\\u8BF8\\u5982\\u6279\\u5904\\u7406 DOM \\u66F4\\u6539\\u3001\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"documentFragment\"}),\" \\u5904\\u7406\\u591A\\u4E2A\\u5143\\u7D20\\u4EE5\\u53CA\\u5229\\u7528 React \\u7B49\\u865A\\u62DF DOM \\u5E93\\u7B49\\u6280\\u672F\\u3002\\u6B64\\u5916\\uFF0C\\u8FD8\\u53EF\\u4EE5\\u8003\\u8651\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" \\u8FDB\\u884C\\u52A8\\u753B\\u5904\\u7406\\uFF0C\\u5E76\\u901A\\u8FC7\\u5206\\u522B\\u8BFB\\u53D6\\u548C\\u5199\\u5165 DOM \\u5C5E\\u6027\\u6765\\u907F\\u514D\\u5E03\\u5C40\\u6296\\u52A8\\u3002\"]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5982\\u4F55\\u4F18\\u5316 DOM \\u64CD\\u4F5C\\u4EE5\\u83B7\\u5F97\\u66F4\\u597D\\u7684\\u6027\\u80FD\\uFF1F\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5C3D\\u91CF\\u51CF\\u5C11\\u76F4\\u63A5 DOM \\u8BBF\\u95EE\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BBF\\u95EE DOM \\u76F8\\u5BF9\\u8F83\\u6162\\uFF0C\\u56E0\\u6B64\\u8BF7\\u5C3D\\u91CF\\u51CF\\u5C11\\u4ECE DOM \\u8BFB\\u53D6\\u6216\\u5199\\u5165 DOM \\u7684\\u6B21\\u6570\\u3002\\u76F8\\u53CD\\uFF0C\\u5C06\\u5BF9\\u5143\\u7D20\\u7684\\u5F15\\u7528\\u5B58\\u50A8\\u5728\\u53D8\\u91CF\\u4E2D\\uFF0C\\u5E76\\u4F7F\\u7528\\u8FD9\\u4E9B\\u53D8\\u91CF\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement'); // Access once\n// Then use the reference to edit style\nelement.style.color = 'red';\nelement.style.backgroundColor = 'blue';\n\nconsole.log(document.body); // Notice the edits\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6279\\u5904\\u7406 DOM \\u66F4\\u6539\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E0D\\u8981\\u4E00\\u6B21\\u5BF9 DOM \\u8FDB\\u884C\\u591A\\u6B21\\u66F4\\u6539\\uFF0C\\u800C\\u662F\\u5C06\\u5B83\\u4EEC\\u6279\\u5904\\u7406\\u5728\\u4E00\\u8D77\\u3002\\u8FD9\\u51CF\\u5C11\\u4E86\\u91CD\\u6392\\u548C\\u91CD\\u7ED8\\u7684\\u6B21\\u6570\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement');\nelement.style.cssText = 'color: red; background-color: blue;';\n\nconsole.log(document.body); // Notice the edits\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"documentFragment\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5C06\\u591A\\u4E2A\\u5143\\u7D20\\u6DFB\\u52A0\\u5230 DOM \\u65F6\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"documentFragment\"}),\" \\u4EE5\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u91CD\\u6392\\u548C\\u91CD\\u7ED8\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const fragment = document.createDocumentFragment();\nfor (let i = 0; i < 100; i++) {\n const newElement = document.createElement('div');\n newElement.textContent = \\`Item \\${i}\\`;\n fragment.appendChild(newElement);\n}\ndocument.body.appendChild(fragment);\n\nconsole.log(document.body); // Notice that the divs have been added\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5229\\u7528\\u865A\\u62DF DOM \\u5E93\"}),`\n`,(0,n.jsx)(e.p,{children:\"React \\u7B49\\u5E93\\u4F7F\\u7528\\u865A\\u62DF DOM \\u6765\\u6279\\u5904\\u7406\\u66F4\\u65B0\\u5E76\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u76F4\\u63A5 DOM \\u64CD\\u4F5C\\uFF0C\\u8FD9\\u53EF\\u4EE5\\u663E\\u8457\\u63D0\\u9AD8\\u6027\\u80FD\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`import React from 'react';\nimport ReactDOM from 'react-dom';\n\nconst App = () => (\n \n
Hello, world! \n \n);\n\nReactDOM.render( , document.getElementById('root'));\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" \\u8FDB\\u884C\\u52A8\\u753B\\u5904\\u7406\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E3A\\u4E86\\u83B7\\u5F97\\u66F4\\u6D41\\u7545\\u7684\\u52A8\\u753B\\u6548\\u679C\\uFF0C\\u8BF7\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" \\u786E\\u4FDD\\u66F4\\u65B0\\u4E0E\\u6D4F\\u89C8\\u5668\\u7684\\u91CD\\u7ED8\\u5468\\u671F\\u540C\\u6B65\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`function animate() {\n // Update animation state\n requestAnimationFrame(animate);\n}\nrequestAnimationFrame(animate);\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u907F\\u514D\\u5E03\\u5C40\\u6296\\u52A8\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5F53\\u60A8\\u4EE5\\u8FEB\\u4F7F\\u6D4F\\u89C8\\u5668\\u591A\\u6B21\\u91CD\\u65B0\\u8BA1\\u7B97\\u6837\\u5F0F\\u548C\\u5E03\\u5C40\\u7684\\u65B9\\u5F0F\\u53CD\\u590D\\u8BFB\\u53D6\\u548C\\u5199\\u5165 DOM \\u65F6\\uFF0C\\u5C31\\u4F1A\\u53D1\\u751F\\u5E03\\u5C40\\u6296\\u52A8\\u3002\\u4E3A\\u907F\\u514D\\u8FD9\\u79CD\\u60C5\\u51B5\\uFF0C\\u8BF7\\u5C06\\u8BFB\\u53D6\\u548C\\u5199\\u5165\\u64CD\\u4F5C\\u5206\\u5F00\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement');\nconst height = element.clientHeight; // Read\nelement.style.height = \\`\\${height + 10}px\\`; // Write\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame\",children:\"MDN Web Docs: Using requestAnimationFrame\"})}),`\n`]})]})}function b(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(a,t)})):a(t)}var w=b;return y(f);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var c=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var D=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),M=(t,e)=>{for(var l in e)c(t,l,{get:e[l],enumerable:!0})},d=(t,e,l,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of u(e))!g.call(t,o)&&o!==l&&c(t,o,{get:()=>e[o],enumerable:!(r=s(e,o))||r.enumerable});return t};var y=(t,e,l)=>(l=t!=null?h(p(t)):{},d(e||!t||!t.__esModule?c(l,\"default\",{value:t,enumerable:!0}):l,t)),E=t=>d(c({},\"__esModule\",{value:!0}),t);var a=D((x,i)=>{i.exports=_jsx_runtime});var w={};M(w,{default:()=>f,frontmatter:()=>O});var n=y(a()),O={title:\"\\u5982\\u4F55\\u4F18\\u5316 DOM \\u64CD\\u4F5C\\u4EE5\\u83B7\\u5F97\\u66F4\\u597D\\u7684\\u6027\\u80FD\\uFF1F\"};function m(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",pre:\"pre\",ul:\"ul\",li:\"li\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8981\\u4F18\\u5316 DOM \\u64CD\\u4F5C\\u4EE5\\u83B7\\u5F97\\u66F4\\u597D\\u7684\\u6027\\u80FD\\uFF0C\\u8BF7\\u5C3D\\u91CF\\u51CF\\u5C11\\u76F4\\u63A5\\u8BBF\\u95EE\\u548C\\u66F4\\u65B0 DOM\\u3002\\u4F7F\\u7528\\u8BF8\\u5982\\u6279\\u5904\\u7406 DOM \\u66F4\\u6539\\u3001\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"documentFragment\"}),\" \\u5904\\u7406\\u591A\\u4E2A\\u5143\\u7D20\\u4EE5\\u53CA\\u5229\\u7528 React \\u7B49\\u865A\\u62DF DOM \\u5E93\\u7B49\\u6280\\u672F\\u3002\\u6B64\\u5916\\uFF0C\\u8FD8\\u53EF\\u4EE5\\u8003\\u8651\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" \\u8FDB\\u884C\\u52A8\\u753B\\u5904\\u7406\\uFF0C\\u5E76\\u901A\\u8FC7\\u5206\\u522B\\u8BFB\\u53D6\\u548C\\u5199\\u5165 DOM \\u5C5E\\u6027\\u6765\\u907F\\u514D\\u5E03\\u5C40\\u6296\\u52A8\\u3002\"]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5982\\u4F55\\u4F18\\u5316 DOM \\u64CD\\u4F5C\\u4EE5\\u83B7\\u5F97\\u66F4\\u597D\\u7684\\u6027\\u80FD\\uFF1F\"}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5C3D\\u91CF\\u51CF\\u5C11\\u76F4\\u63A5 DOM \\u8BBF\\u95EE\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u8BBF\\u95EE DOM \\u76F8\\u5BF9\\u8F83\\u6162\\uFF0C\\u56E0\\u6B64\\u8BF7\\u5C3D\\u91CF\\u51CF\\u5C11\\u4ECE DOM \\u8BFB\\u53D6\\u6216\\u5199\\u5165 DOM \\u7684\\u6B21\\u6570\\u3002\\u76F8\\u53CD\\uFF0C\\u5C06\\u5BF9\\u5143\\u7D20\\u7684\\u5F15\\u7528\\u5B58\\u50A8\\u5728\\u53D8\\u91CF\\u4E2D\\uFF0C\\u5E76\\u4F7F\\u7528\\u8FD9\\u4E9B\\u53D8\\u91CF\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement'); // Access once\n// Then use the reference to edit style\nelement.style.color = 'red';\nelement.style.backgroundColor = 'blue';\n\nconsole.log(document.body); // Notice the edits\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u6279\\u5904\\u7406 DOM \\u66F4\\u6539\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u4E0D\\u8981\\u4E00\\u6B21\\u5BF9 DOM \\u8FDB\\u884C\\u591A\\u6B21\\u66F4\\u6539\\uFF0C\\u800C\\u662F\\u5C06\\u5B83\\u4EEC\\u6279\\u5904\\u7406\\u5728\\u4E00\\u8D77\\u3002\\u8FD9\\u51CF\\u5C11\\u4E86\\u91CD\\u6392\\u548C\\u91CD\\u7ED8\\u7684\\u6B21\\u6570\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement');\nelement.style.cssText = 'color: red; background-color: blue;';\n\nconsole.log(document.body); // Notice the edits\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"documentFragment\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5C06\\u591A\\u4E2A\\u5143\\u7D20\\u6DFB\\u52A0\\u5230 DOM \\u65F6\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"documentFragment\"}),\" \\u4EE5\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u91CD\\u6392\\u548C\\u91CD\\u7ED8\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const fragment = document.createDocumentFragment();\nfor (let i = 0; i < 100; i++) {\n const newElement = document.createElement('div');\n newElement.textContent = \\`Item \\${i}\\`;\n fragment.appendChild(newElement);\n}\ndocument.body.appendChild(fragment);\n\nconsole.log(document.body); // Notice that the divs have been added\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5229\\u7528\\u865A\\u62DF DOM \\u5E93\"}),`\n`,(0,n.jsx)(e.p,{children:\"React \\u7B49\\u5E93\\u4F7F\\u7528\\u865A\\u62DF DOM \\u6765\\u6279\\u5904\\u7406\\u66F4\\u65B0\\u5E76\\u6700\\u5927\\u9650\\u5EA6\\u5730\\u51CF\\u5C11\\u76F4\\u63A5 DOM \\u64CD\\u4F5C\\uFF0C\\u8FD9\\u53EF\\u4EE5\\u663E\\u8457\\u63D0\\u9AD8\\u6027\\u80FD\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`import React from 'react';\nimport ReactDOM from 'react-dom';\n\nconst App = () => (\n \n
Hello, world! \n \n);\n\nReactDOM.render( , document.getElementById('root'));\n`})}),`\n`,(0,n.jsxs)(e.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" \\u8FDB\\u884C\\u52A8\\u753B\\u5904\\u7406\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4E3A\\u4E86\\u83B7\\u5F97\\u66F4\\u6D41\\u7545\\u7684\\u52A8\\u753B\\u6548\\u679C\\uFF0C\\u8BF7\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"requestAnimationFrame\"}),\" \\u786E\\u4FDD\\u66F4\\u65B0\\u4E0E\\u6D4F\\u89C8\\u5668\\u7684\\u91CD\\u7ED8\\u5468\\u671F\\u540C\\u6B65\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`function animate() {\n // Update animation state\n requestAnimationFrame(animate);\n}\nrequestAnimationFrame(animate);\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u907F\\u514D\\u5E03\\u5C40\\u6296\\u52A8\"}),`\n`,(0,n.jsx)(e.p,{children:\"\\u5F53\\u60A8\\u4EE5\\u8FEB\\u4F7F\\u6D4F\\u89C8\\u5668\\u591A\\u6B21\\u91CD\\u65B0\\u8BA1\\u7B97\\u6837\\u5F0F\\u548C\\u5E03\\u5C40\\u7684\\u65B9\\u5F0F\\u53CD\\u590D\\u8BFB\\u53D6\\u548C\\u5199\\u5165 DOM \\u65F6\\uFF0C\\u5C31\\u4F1A\\u53D1\\u751F\\u5E03\\u5C40\\u6296\\u52A8\\u3002\\u4E3A\\u907F\\u514D\\u8FD9\\u79CD\\u60C5\\u51B5\\uFF0C\\u8BF7\\u5C06\\u8BFB\\u53D6\\u548C\\u5199\\u5165\\u64CD\\u4F5C\\u5206\\u5F00\\u3002\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// Creating an element for the example below\nconst newElement = document.createElement('div');\nnewElement.id = 'myElement';\ndocument.body.appendChild(newElement);\n\nconst element = document.getElementById('myElement');\nconst height = element.clientHeight; // Read\nelement.style.height = \\`\\${height + 10}px\\`; // Write\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Manipulating_the_DOM\",children:\"MDN Web Docs: DOM manipulation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developers.google.com/web/fundamentals/performance/rendering/avoid-large-complex-layouts-and-layout-thrashing\",children:\"Google Developers: Avoid large, complex layouts and layout thrashing\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn\",children:\"React documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame\",children:\"MDN Web Docs: Using requestAnimationFrame\"})}),`\n`]})]})}function b(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(m,t)})):m(t)}var f=b;return E(w);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-abort-a-web-request-using-abortcontrollers/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-do-you-abort-a-web-request-using-abortcontrollers/locales/en-US.json
index 6212a2400..792ed012d 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-abort-a-web-request-using-abortcontrollers/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-abort-a-web-request-using-abortcontrollers/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How do you abort a web request using `AbortController` in JavaScript?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-do-you-abort-a-web-request-using-abortcontrollers/en-US.mdx"
},
- "solution": "var Component=(()=>{var d=Object.create;var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var m=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),f=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},c=(r,e,t,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of p(e))!b.call(r,o)&&o!==t&&l(r,o,{get:()=>e[o],enumerable:!(s=u(e,o))||s.enumerable});return r};var C=(r,e,t)=>(t=r!=null?d(g(r)):{},c(e||!r||!r.__esModule?l(t,\"default\",{value:r,enumerable:!0}):t,r)),q=r=>c(l({},\"__esModule\",{value:!0}),r);var a=m((k,i)=>{i.exports=_jsx_runtime});var v={};f(v,{default:()=>A,frontmatter:()=>w});var n=C(a()),w={title:\"How do you abort a web request using `AbortController` in JavaScript?\"};function h(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",ul:\"ul\",li:\"li\",hr:\"hr\",ol:\"ol\",strong:\"strong\",h3:\"h3\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"AbortController\"}),\" is used to cancel ongoing asynchronous operations like fetch requests.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request aborted');\n } else {\n console.error('Error:', error);\n }\n });\n\n// Call abort() to abort the request\ncontroller.abort();\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"Aborting web requests is useful for:\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Canceling requests based on user actions.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Prioritizing the latest requests in scenarios with multiple simultaneous requests.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Canceling requests that are no longer needed, e.g. after the user has navigated away from the page.\"}),`\n`]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsxs)(e.h2,{children:[(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"AbortController\"}),\" allows graceful cancelation of ongoing asynchronous operations like fetch requests. It offers a mechanism to signal to the underlying network layer that the request is no longer required, preventing unnecessary resource consumption and improving user experience.\"]}),`\n`,(0,n.jsxs)(e.h2,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s involve the following steps:\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Create an \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\" instance\"]}),\": Initialize an \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\" instance, which creates a signal that can be used to abort requests.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Pass the signal to the request\"}),\": Pass the signal to the request, typically through the \",(0,n.jsx)(e.code,{children:\"signal\"}),\" property in the request options.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Abort the request\"}),\": Call the \",(0,n.jsx)(e.code,{children:\"abort()\"}),\" method on the \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\" instance to cancel the ongoing request.\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Here is an example of how to use \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s with the \",(0,n.jsx)(e.code,{children:\"fetch()\"}),\" API:\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request aborted');\n } else {\n console.error('Error:', error);\n }\n });\n\n// Call abort() to abort the request\ncontroller.abort();\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Use cases\"}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Canceling a \",(0,n.jsx)(e.code,{children:\"fetch()\"}),\" request on a user action\"]}),`\n`,(0,n.jsx)(e.p,{children:\"Cancel requests that take too long or are no longer relevant due to user interactions (e.g., user cancels uploading of a huge file).\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// HTML: Cancel upload \nconst btn = document.createElement('button');\nbtn.id = 'cancel-button';\nbtn.innerHTML = 'Cancel upload';\ndocument.body.appendChild(btn);\n\nconst controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle successful response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request canceled');\n } else {\n console.error('Network or other error:', error);\n }\n });\n\ndocument.getElementById('cancel-button').addEventListener('click', () => {\n controller.abort();\n});\ndocument.getElementById('cancel-button').click(); // Simulate clicking the cancel button\n`})}),`\n`,(0,n.jsx)(e.p,{children:'When you click the \"Cancel upload\" button, in-flight request will be aborted.'}),`\n`,(0,n.jsx)(e.h3,{children:\"Prioritizing latest requests in a race condition\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In scenarios where multiple requests are initiated for the same data, use \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\" to prioritize the latest request and abort earlier ones.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`let latestController = null; // Keeps track of the latest controller\n\nfunction fetchData(url) {\n if (latestController) {\n latestController.abort(); // Abort any previous request\n }\n\n const controller = new AbortController();\n latestController = controller;\n const signal = controller.signal;\n\n fetch(url, { signal })\n .then((response) => response.json())\n .then((data) => console.log('Fetched data:', data))\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request canceled');\n } else {\n console.error('Network or other error:', error);\n }\n });\n}\n\nfetchData('https://jsonplaceholder.typicode.com/posts/1');\n\n// Simulate race conditions with new requests that quickly cancel the previous one\nsetTimeout(() => {\n fetchData('https://jsonplaceholder.typicode.com/posts/2');\n}, 5);\nsetTimeout(() => {\n fetchData('https://jsonplaceholder.typicode.com/posts/3');\n}, 5);\n// Only the last request should (posts/3) will be allowed to complete\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"In this example, when the \",(0,n.jsx)(e.code,{children:\"fetchData()\"}),\" function is called multiple times triggering multiple fetch requests, \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s will cancel all the previous requests except the latest request. This is common in scenarios like type-ahead search or infinite scrolling, where new requests are triggered frequently.\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Canceling requests that are no longer needed\"}),`\n`,(0,n.jsx)(e.p,{children:\"In situations where the user has navigated away from the page, aborting the request can prevent unnecessary operations (e.g. success callback handling), and freeing up resources by lowering the likelihood of memory leaks.\"}),`\n`,(0,n.jsx)(e.h2,{children:\"Notes\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s is not \",(0,n.jsx)(e.code,{children:\"fetch()\"}),\"-specific, it can be used to abort other asynchronous tasks as well.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"A singular \",(0,n.jsx)(e.code,{children:\"AbortContoller\"}),\" instance can be reused or multiple async tasks and cancel all of them at once.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Calling \",(0,n.jsx)(e.code,{children:\"abort()\"}),\" on \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s does not send any notification or signal to the server. The server is unaware of the cancelation and will continue processing the request until it completes or times out.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/AbortController\",children:\"AbortController | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://javascript.info/fetch-abort\",children:\"Fetch: Abort | Javascript.info\"})}),`\n`]})]})}function y(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(h,r)})):h(r)}var A=y;return q(v);})();\n;return Component;"
+ "solution": "var Component=(()=>{var d=Object.create;var l=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var m=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),f=(r,e)=>{for(var t in e)l(r,t,{get:e[t],enumerable:!0})},c=(r,e,t,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of p(e))!b.call(r,o)&&o!==t&&l(r,o,{get:()=>e[o],enumerable:!(s=u(e,o))||s.enumerable});return r};var C=(r,e,t)=>(t=r!=null?d(g(r)):{},c(e||!r||!r.__esModule?l(t,\"default\",{value:r,enumerable:!0}):t,r)),q=r=>c(l({},\"__esModule\",{value:!0}),r);var a=m((k,i)=>{i.exports=_jsx_runtime});var v={};f(v,{default:()=>A,frontmatter:()=>w});var n=C(a()),w={title:\"How do you abort a web request using `AbortController` in JavaScript?\"};function h(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",ul:\"ul\",li:\"li\",hr:\"hr\",ol:\"ol\",strong:\"strong\",h3:\"h3\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"AbortController\"}),\" is used to cancel ongoing asynchronous operations like fetch requests.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request aborted');\n } else {\n console.error('Error:', error);\n }\n });\n\n// Call abort() to abort the request\ncontroller.abort();\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"Aborting web requests is useful for:\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Canceling requests based on user actions.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Prioritizing the latest requests in scenarios with multiple simultaneous requests.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Canceling requests that are no longer needed, e.g. after the user has navigated away from the page.\"}),`\n`]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsxs)(e.h2,{children:[(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s\"]}),`\n`,(0,n.jsxs)(e.p,{children:[(0,n.jsx)(e.code,{children:\"AbortController\"}),\" allows graceful cancelation of ongoing asynchronous operations like fetch requests. It offers a mechanism to signal to the underlying network layer that the request is no longer required, preventing unnecessary resource consumption and improving user experience.\"]}),`\n`,(0,n.jsxs)(e.h2,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s involve the following steps:\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsxs)(e.strong,{children:[\"Create an \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\" instance\"]}),\": Initialize an \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\" instance, which creates a signal that can be used to abort requests.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Pass the signal to the request\"}),\": Pass the signal to the request, typically through the \",(0,n.jsx)(e.code,{children:\"signal\"}),\" property in the request options.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Abort the request\"}),\": Call the \",(0,n.jsx)(e.code,{children:\"abort()\"}),\" method on the \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\" instance to cancel the ongoing request.\"]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Here is an example of how to use \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s with the \",(0,n.jsx)(e.code,{children:\"fetch()\"}),\" API:\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request aborted');\n } else {\n console.error('Error:', error);\n }\n });\n\n// Call abort() to abort the request\ncontroller.abort();\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Use cases\"}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Canceling a \",(0,n.jsx)(e.code,{children:\"fetch()\"}),\" request on a user action\"]}),`\n`,(0,n.jsx)(e.p,{children:\"Cancel requests that take too long or are no longer relevant due to user interactions (e.g., user cancels uploading of a huge file).\"}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`// HTML: Cancel upload \nconst btn = document.createElement('button');\nbtn.id = 'cancel-button';\nbtn.innerHTML = 'Cancel upload';\ndocument.body.appendChild(btn);\n\nconst controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle successful response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request canceled');\n } else {\n console.error('Network or other error:', error);\n }\n });\n\ndocument.getElementById('cancel-button').addEventListener('click', () => {\n controller.abort();\n});\ndocument.getElementById('cancel-button').click(); // Simulate clicking the cancel button\n`})}),`\n`,(0,n.jsx)(e.p,{children:'When you click the \"Cancel upload\" button, in-flight request will be aborted.'}),`\n`,(0,n.jsx)(e.h3,{children:\"Prioritizing latest requests in a race condition\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In scenarios where multiple requests are initiated for the same data, use \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\" to prioritize the latest request and abort earlier ones.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`let latestController = null; // Keeps track of the latest controller\n\nfunction fetchData(url) {\n if (latestController) {\n latestController.abort(); // Abort any previous request\n }\n\n const controller = new AbortController();\n latestController = controller;\n const signal = controller.signal;\n\n fetch(url, { signal })\n .then((response) => response.json())\n .then((data) => console.log('Fetched data:', data))\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request canceled');\n } else {\n console.error('Network or other error:', error);\n }\n });\n}\n\nfetchData('https://jsonplaceholder.typicode.com/posts/1');\n\n// Simulate race conditions with new requests that quickly cancel the previous one\nsetTimeout(() => {\n fetchData('https://jsonplaceholder.typicode.com/posts/2');\n}, 5);\nsetTimeout(() => {\n fetchData('https://jsonplaceholder.typicode.com/posts/3');\n}, 5);\n// Only the last request should (posts/3) will be allowed to complete\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"In this example, when the \",(0,n.jsx)(e.code,{children:\"fetchData()\"}),\" function is called multiple times triggering multiple fetch requests, \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s will cancel all the previous requests except the latest request. This is common in scenarios like type-ahead search or infinite scrolling, where new requests are triggered frequently.\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Canceling requests that are no longer needed\"}),`\n`,(0,n.jsx)(e.p,{children:\"In situations where the user has navigated away from the page, aborting the request can prevent unnecessary operations (e.g. success callback handling), and freeing up resources by lowering the likelihood of memory leaks.\"}),`\n`,(0,n.jsx)(e.h2,{children:\"Notes\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s is not \",(0,n.jsx)(e.code,{children:\"fetch()\"}),\"-specific, it can be used to abort other asynchronous tasks as well.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"A singular \",(0,n.jsx)(e.code,{children:\"AbortContoller\"}),\" instance can be reused on multiple async tasks and cancel all of them at once.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[\"Calling \",(0,n.jsx)(e.code,{children:\"abort()\"}),\" on \",(0,n.jsx)(e.code,{children:\"AbortController\"}),\"s does not send any notification or signal to the server. The server is unaware of the cancelation and will continue processing the request until it completes or times out.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/AbortController\",children:\"AbortController | MDN\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://javascript.info/fetch-abort\",children:\"Fetch: Abort | Javascript.info\"})}),`\n`]})]})}function y(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(h,r)})):h(r)}var A=y;return q(v);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-abort-a-web-request-using-abortcontrollers/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/how-do-you-abort-a-web-request-using-abortcontrollers/locales/zh-CN.json
index 5564e8479..b270358bd 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-abort-a-web-request-using-abortcontrollers/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-abort-a-web-request-using-abortcontrollers/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "如何在 JavaScript 中使用 `AbortController` 终止 Web 请求?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-do-you-abort-a-web-request-using-abortcontrollers/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var a=Object.create;var t=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),f=(r,n)=>{for(var o in n)t(r,o,{get:n[o],enumerable:!0})},d=(r,n,o,c)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let l of b(n))!g.call(r,l)&&l!==o&&t(r,l,{get:()=>n[l],enumerable:!(c=p(n,l))||c.enumerable});return r};var C=(r,n,o)=>(o=r!=null?a(u(r)):{},d(n||!r||!r.__esModule?t(o,\"default\",{value:r,enumerable:!0}):o,r)),A=r=>d(t({},\"__esModule\",{value:!0}),r);var s=m((E,i)=>{i.exports=_jsx_runtime});var w={};f(w,{default:()=>v,frontmatter:()=>j});var e=C(s()),j={title:\"\\u5982\\u4F55\\u5728 JavaScript \\u4E2D\\u4F7F\\u7528 `AbortController` \\u7EC8\\u6B62 Web \\u8BF7\\u6C42\\uFF1F\"};function h(r){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",ul:\"ul\",li:\"li\",hr:\"hr\",ol:\"ol\",strong:\"strong\",h3:\"h3\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u7528\\u4E8E\\u53D6\\u6D88\\u8FDB\\u884C\\u4E2D\\u7684\\u5F02\\u6B65\\u64CD\\u4F5C\\uFF0C\\u4F8B\\u5982 fetch \\u8BF7\\u6C42\\u3002\"]}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request aborted');\n } else {\n console.error('Error:', error);\n }\n });\n\n// Call abort() to abort the request\ncontroller.abort();\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7EC8\\u6B62 Web \\u8BF7\\u6C42\\u5BF9\\u4E8E\\u4EE5\\u4E0B\\u60C5\\u51B5\\u5F88\\u6709\\u7528\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u6839\\u636E\\u7528\\u6237\\u64CD\\u4F5C\\u53D6\\u6D88\\u8BF7\\u6C42\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5728\\u6709\\u591A\\u4E2A\\u5E76\\u53D1\\u8BF7\\u6C42\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u4F18\\u5148\\u5904\\u7406\\u6700\\u65B0\\u7684\\u8BF7\\u6C42\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u53D6\\u6D88\\u4E0D\\u518D\\u9700\\u8981\\u7684\\u8BF7\\u6C42\\uFF0C\\u4F8B\\u5982\\uFF0C\\u5728\\u7528\\u6237\\u5DF2\\u4ECE\\u9875\\u9762\\u5BFC\\u822A\\u79BB\\u5F00\\u4E4B\\u540E\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsxs)(n.h2,{children:[(0,e.jsx)(n.code,{children:\"AbortController\"}),\"s\"]}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5141\\u8BB8\\u4F18\\u96C5\\u5730\\u53D6\\u6D88\\u8FDB\\u884C\\u4E2D\\u7684\\u5F02\\u6B65\\u64CD\\u4F5C\\uFF0C\\u4F8B\\u5982 fetch \\u8BF7\\u6C42\\u3002 \\u5B83\\u63D0\\u4F9B\\u4E86\\u4E00\\u79CD\\u673A\\u5236\\uFF0C\\u5411\\u5E95\\u5C42\\u7F51\\u7EDC\\u5C42\\u53D1\\u51FA\\u4FE1\\u53F7\\uFF0C\\u8868\\u660E\\u4E0D\\u518D\\u9700\\u8981\\u8BE5\\u8BF7\\u6C42\\uFF0C\\u4ECE\\u800C\\u9632\\u6B62\\u4E0D\\u5FC5\\u8981\\u7684\\u8D44\\u6E90\\u6D88\\u8017\\u5E76\\u6539\\u5584\\u7528\\u6237\\u4F53\\u9A8C\\u3002\"]}),`\n`,(0,e.jsxs)(n.h2,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\"s\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u6D89\\u53CA\\u4EE5\\u4E0B\\u6B65\\u9AA4\\uFF1A\"]}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u521B\\u5EFA \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5B9E\\u4F8B\"]}),\"\\uFF1A\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5B9E\\u4F8B\\uFF0C\\u5B83\\u4F1A\\u521B\\u5EFA\\u4E00\\u4E2A\\u53EF\\u7528\\u4E8E\\u4E2D\\u6B62\\u8BF7\\u6C42\\u7684\\u4FE1\\u53F7\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5C06\\u4FE1\\u53F7\\u4F20\\u9012\\u7ED9\\u8BF7\\u6C42\"}),\"\\uFF1A\\u5C06\\u4FE1\\u53F7\\u4F20\\u9012\\u7ED9\\u8BF7\\u6C42\\uFF0C\\u901A\\u5E38\\u901A\\u8FC7\\u8BF7\\u6C42\\u9009\\u9879\\u4E2D\\u7684 \",(0,e.jsx)(n.code,{children:\"signal\"}),\" \\u5C5E\\u6027\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E2D\\u6B62\\u8BF7\\u6C42\"}),\"\\uFF1A\\u5728 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5B9E\\u4F8B\\u4E0A\\u8C03\\u7528 \",(0,e.jsx)(n.code,{children:\"abort()\"}),\" \\u65B9\\u6CD5\\u4EE5\\u53D6\\u6D88\\u6B63\\u5728\\u8FDB\\u884C\\u7684\\u8BF7\\u6C42\\u3002\"]}),`\n`]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u4EE5\\u4E0B\\u662F\\u5982\\u4F55\\u5C06 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u4E0E \",(0,e.jsx)(n.code,{children:\"fetch()\"}),\" API \\u7ED3\\u5408\\u4F7F\\u7528\\u7684\\u793A\\u4F8B\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request aborted');\n } else {\n console.error('Error:', error);\n }\n });\n\n// Call abort() to abort the request\ncontroller.abort();\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u7528\\u4F8B\"}),`\n`,(0,e.jsxs)(n.h3,{children:[\"\\u5728\\u7528\\u6237\\u64CD\\u4F5C\\u65F6\\u53D6\\u6D88 \",(0,e.jsx)(n.code,{children:\"fetch()\"}),\" \\u8BF7\\u6C42\"]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u53D6\\u6D88\\u7531\\u4E8E\\u7528\\u6237\\u4EA4\\u4E92\\uFF08\\u4F8B\\u5982\\uFF0C\\u7528\\u6237\\u53D6\\u6D88\\u4E0A\\u4F20\\u4E00\\u4E2A\\u5927\\u6587\\u4EF6\\uFF09\\u800C\\u5BFC\\u81F4\\u8017\\u65F6\\u8FC7\\u957F\\u6216\\u4E0D\\u518D\\u76F8\\u5173\\u7684\\u8BF7\\u6C42\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`// HTML: Cancel upload \nconst btn = document.createElement('button');\nbtn.id = 'cancel-button';\nbtn.innerHTML = 'Cancel upload';\ndocument.body.appendChild(btn);\n\nconst controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle successful response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request canceled');\n } else {\n console.error('Network or other error:', error);\n }\n });\n\ndocument.getElementById('cancel-button').addEventListener('click', () => {\n controller.abort();\n});\ndocument.getElementById('cancel-button').click(); // Simulate clicking the cancel button\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5F53\\u60A8\\u5355\\u51FB\\u201C\\u53D6\\u6D88\\u4E0A\\u4F20\\u201D\\u6309\\u94AE\\u65F6\\uFF0C\\u6B63\\u5728\\u8FDB\\u884C\\u7684\\u8BF7\\u6C42\\u5C06\\u88AB\\u4E2D\\u6B62\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5728\\u7ADE\\u4E89\\u6761\\u4EF6\\u4E0B\\u4F18\\u5148\\u5904\\u7406\\u6700\\u65B0\\u8BF7\\u6C42\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u4E3A\\u76F8\\u540C\\u6570\\u636E\\u542F\\u52A8\\u591A\\u4E2A\\u8BF7\\u6C42\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u4F18\\u5148\\u5904\\u7406\\u6700\\u65B0\\u8BF7\\u6C42\\u5E76\\u4E2D\\u6B62\\u8F83\\u65E9\\u7684\\u8BF7\\u6C42\\u3002\"]}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`let latestController = null; // Keeps track of the latest controller\n\nfunction fetchData(url) {\n if (latestController) {\n latestController.abort(); // Abort any previous request\n }\n\n const controller = new AbortController();\n latestController = controller;\n const signal = controller.signal;\n\n fetch(url, { signal })\n .then((response) => response.json())\n .then((data) => console.log('Fetched data:', data))\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request canceled');\n } else {\n console.error('Network or other error:', error);\n }\n });\n}\n\nfetchData('https://jsonplaceholder.typicode.com/posts/1');\n\n// Simulate race conditions with new requests that quickly cancel the previous one\nsetTimeout(() => {\n fetchData('https://jsonplaceholder.typicode.com/posts/2');\n}, 5);\nsetTimeout(() => {\n fetchData('https://jsonplaceholder.typicode.com/posts/3');\n}, 5);\n// Only the last request should (posts/3) will be allowed to complete\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u672C\\u4F8B\\u4E2D\\uFF0C\\u5F53\\u591A\\u6B21\\u8C03\\u7528 \",(0,e.jsx)(n.code,{children:\"fetchData()\"}),\" \\u51FD\\u6570\\u89E6\\u53D1\\u591A\\u4E2A fetch \\u8BF7\\u6C42\\u65F6\\uFF0C\",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5C06\\u53D6\\u6D88\\u6240\\u6709\\u4E4B\\u524D\\u7684\\u8BF7\\u6C42\\uFF0C\\u9664\\u4E86\\u6700\\u65B0\\u7684\\u8BF7\\u6C42\\u3002\\u8FD9\\u5728\\u8BF8\\u5982\\u7C7B\\u578B\\u63D0\\u793A\\u641C\\u7D22\\u6216\\u65E0\\u9650\\u6EDA\\u52A8\\u7B49\\u573A\\u666F\\u4E2D\\u5F88\\u5E38\\u89C1\\uFF0C\\u5728\\u8FD9\\u4E9B\\u573A\\u666F\\u4E2D\\uFF0C\\u4F1A\\u9891\\u7E41\\u89E6\\u53D1\\u65B0\\u7684\\u8BF7\\u6C42\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u53D6\\u6D88\\u4E0D\\u518D\\u9700\\u8981\\u7684\\u8BF7\\u6C42\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5728\\u7528\\u6237\\u5DF2\\u4ECE\\u9875\\u9762\\u5BFC\\u822A\\u51FA\\u53BB\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u4E2D\\u6B62\\u8BF7\\u6C42\\u53EF\\u4EE5\\u9632\\u6B62\\u4E0D\\u5FC5\\u8981\\u7684\\u64CD\\u4F5C\\uFF08\\u4F8B\\u5982\\uFF0C\\u6210\\u529F\\u56DE\\u8C03\\u5904\\u7406\\uFF09\\uFF0C\\u5E76\\u901A\\u8FC7\\u964D\\u4F4E\\u5185\\u5B58\\u6CC4\\u6F0F\\u7684\\u53EF\\u80FD\\u6027\\u6765\\u91CA\\u653E\\u8D44\\u6E90\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u7B14\\u8BB0\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5E76\\u975E \",(0,e.jsx)(n.code,{children:\"fetch()\"}),\" \\u4E13\\u6709\\uFF0C\\u5B83\\u4E5F\\u53EF\\u4EE5\\u7528\\u4E8E\\u4E2D\\u6B62\\u5176\\u4ED6\\u5F02\\u6B65\\u4EFB\\u52A1\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4E00\\u4E2A\\u5355\\u72EC\\u7684 \",(0,e.jsx)(n.code,{children:\"AbortContoller\"}),\" \\u5B9E\\u4F8B\\u53EF\\u4EE5\\u88AB\\u91CD\\u7528\\u6216\\u7528\\u4E8E\\u591A\\u4E2A\\u5F02\\u6B65\\u4EFB\\u52A1\\uFF0C\\u5E76\\u4E00\\u6B21\\u6027\\u53D6\\u6D88\\u6240\\u6709\\u4EFB\\u52A1\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5728 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u4E0A\\u8C03\\u7528 \",(0,e.jsx)(n.code,{children:\"abort()\"}),\" \\u4E0D\\u4F1A\\u5411\\u670D\\u52A1\\u5668\\u53D1\\u9001\\u4EFB\\u4F55\\u901A\\u77E5\\u6216\\u4FE1\\u53F7\\u3002\\u670D\\u52A1\\u5668\\u4E0D\\u77E5\\u9053\\u53D6\\u6D88\\u64CD\\u4F5C\\uFF0C\\u5E76\\u5C06\\u7EE7\\u7EED\\u5904\\u7406\\u8BF7\\u6C42\\uFF0C\\u76F4\\u5230\\u5B83\\u5B8C\\u6210\\u6216\\u8D85\\u65F6\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/AbortController\",children:\"AbortController | MDN\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/fetch-abort\",children:\"Fetch: Abort | Javascript.info\"})}),`\n`]})]})}function y(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(h,r)})):h(r)}var v=y;return A(w);})();\n;return Component;"
+ "solution": "var Component=(()=>{var a=Object.create;var t=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),f=(r,n)=>{for(var o in n)t(r,o,{get:n[o],enumerable:!0})},d=(r,n,o,c)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let l of b(n))!g.call(r,l)&&l!==o&&t(r,l,{get:()=>n[l],enumerable:!(c=p(n,l))||c.enumerable});return r};var C=(r,n,o)=>(o=r!=null?a(u(r)):{},d(n||!r||!r.__esModule?t(o,\"default\",{value:r,enumerable:!0}):o,r)),A=r=>d(t({},\"__esModule\",{value:!0}),r);var s=m((E,i)=>{i.exports=_jsx_runtime});var w={};f(w,{default:()=>v,frontmatter:()=>j});var e=C(s()),j={title:\"\\u5982\\u4F55\\u5728 JavaScript \\u4E2D\\u4F7F\\u7528 `AbortController` \\u7EC8\\u6B62 Web \\u8BF7\\u6C42\\uFF1F\"};function h(r){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",ul:\"ul\",li:\"li\",hr:\"hr\",ol:\"ol\",strong:\"strong\",h3:\"h3\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u7528\\u4E8E\\u53D6\\u6D88\\u8FDB\\u884C\\u4E2D\\u7684\\u5F02\\u6B65\\u64CD\\u4F5C\\uFF0C\\u4F8B\\u5982 fetch \\u8BF7\\u6C42\\u3002\"]}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request aborted');\n } else {\n console.error('Error:', error);\n }\n });\n\n// Call abort() to abort the request\ncontroller.abort();\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7EC8\\u6B62 Web \\u8BF7\\u6C42\\u5BF9\\u4E8E\\u4EE5\\u4E0B\\u60C5\\u51B5\\u5F88\\u6709\\u7528\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u6839\\u636E\\u7528\\u6237\\u64CD\\u4F5C\\u53D6\\u6D88\\u8BF7\\u6C42\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5728\\u6709\\u591A\\u4E2A\\u5E76\\u53D1\\u8BF7\\u6C42\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u4F18\\u5148\\u5904\\u7406\\u6700\\u65B0\\u7684\\u8BF7\\u6C42\\u3002\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u53D6\\u6D88\\u4E0D\\u518D\\u9700\\u8981\\u7684\\u8BF7\\u6C42\\uFF0C\\u4F8B\\u5982\\uFF0C\\u5728\\u7528\\u6237\\u5DF2\\u4ECE\\u9875\\u9762\\u5BFC\\u822A\\u79BB\\u5F00\\u4E4B\\u540E\\u3002\"}),`\n`]}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsxs)(n.h2,{children:[(0,e.jsx)(n.code,{children:\"AbortController\"}),\"s\"]}),`\n`,(0,e.jsxs)(n.p,{children:[(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5141\\u8BB8\\u4F18\\u96C5\\u5730\\u53D6\\u6D88\\u8FDB\\u884C\\u4E2D\\u7684\\u5F02\\u6B65\\u64CD\\u4F5C\\uFF0C\\u4F8B\\u5982 fetch \\u8BF7\\u6C42\\u3002 \\u5B83\\u63D0\\u4F9B\\u4E86\\u4E00\\u79CD\\u673A\\u5236\\uFF0C\\u5411\\u5E95\\u5C42\\u7F51\\u7EDC\\u5C42\\u53D1\\u51FA\\u4FE1\\u53F7\\uFF0C\\u8868\\u660E\\u4E0D\\u518D\\u9700\\u8981\\u8BE5\\u8BF7\\u6C42\\uFF0C\\u4ECE\\u800C\\u9632\\u6B62\\u4E0D\\u5FC5\\u8981\\u7684\\u8D44\\u6E90\\u6D88\\u8017\\u5E76\\u6539\\u5584\\u7528\\u6237\\u4F53\\u9A8C\\u3002\"]}),`\n`,(0,e.jsxs)(n.h2,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\"s\"]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u6D89\\u53CA\\u4EE5\\u4E0B\\u6B65\\u9AA4\\uFF1A\"]}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsxs)(n.strong,{children:[\"\\u521B\\u5EFA \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5B9E\\u4F8B\"]}),\"\\uFF1A\\u521D\\u59CB\\u5316\\u4E00\\u4E2A \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5B9E\\u4F8B\\uFF0C\\u5B83\\u4F1A\\u521B\\u5EFA\\u4E00\\u4E2A\\u53EF\\u7528\\u4E8E\\u4E2D\\u6B62\\u8BF7\\u6C42\\u7684\\u4FE1\\u53F7\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5C06\\u4FE1\\u53F7\\u4F20\\u9012\\u7ED9\\u8BF7\\u6C42\"}),\"\\uFF1A\\u5C06\\u4FE1\\u53F7\\u4F20\\u9012\\u7ED9\\u8BF7\\u6C42\\uFF0C\\u901A\\u5E38\\u901A\\u8FC7\\u8BF7\\u6C42\\u9009\\u9879\\u4E2D\\u7684 \",(0,e.jsx)(n.code,{children:\"signal\"}),\" \\u5C5E\\u6027\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u4E2D\\u6B62\\u8BF7\\u6C42\"}),\"\\uFF1A\\u5728 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5B9E\\u4F8B\\u4E0A\\u8C03\\u7528 \",(0,e.jsx)(n.code,{children:\"abort()\"}),\" \\u65B9\\u6CD5\\u4EE5\\u53D6\\u6D88\\u6B63\\u5728\\u8FDB\\u884C\\u7684\\u8BF7\\u6C42\\u3002\"]}),`\n`]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u4EE5\\u4E0B\\u662F\\u5982\\u4F55\\u5C06 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u4E0E \",(0,e.jsx)(n.code,{children:\"fetch()\"}),\" API \\u7ED3\\u5408\\u4F7F\\u7528\\u7684\\u793A\\u4F8B\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`const controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request aborted');\n } else {\n console.error('Error:', error);\n }\n });\n\n// Call abort() to abort the request\ncontroller.abort();\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u7528\\u4F8B\"}),`\n`,(0,e.jsxs)(n.h3,{children:[\"\\u5728\\u7528\\u6237\\u64CD\\u4F5C\\u65F6\\u53D6\\u6D88 \",(0,e.jsx)(n.code,{children:\"fetch()\"}),\" \\u8BF7\\u6C42\"]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u53D6\\u6D88\\u7531\\u4E8E\\u7528\\u6237\\u4EA4\\u4E92\\uFF08\\u4F8B\\u5982\\uFF0C\\u7528\\u6237\\u53D6\\u6D88\\u4E0A\\u4F20\\u4E00\\u4E2A\\u5927\\u6587\\u4EF6\\uFF09\\u800C\\u5BFC\\u81F4\\u8017\\u65F6\\u8FC7\\u957F\\u6216\\u4E0D\\u518D\\u76F8\\u5173\\u7684\\u8BF7\\u6C42\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`// HTML: Cancel upload \nconst btn = document.createElement('button');\nbtn.id = 'cancel-button';\nbtn.innerHTML = 'Cancel upload';\ndocument.body.appendChild(btn);\n\nconst controller = new AbortController();\nconst signal = controller.signal;\n\nfetch('https://jsonplaceholder.typicode.com/todos/1', { signal })\n .then((response) => {\n // Handle successful response\n })\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request canceled');\n } else {\n console.error('Network or other error:', error);\n }\n });\n\ndocument.getElementById('cancel-button').addEventListener('click', () => {\n controller.abort();\n});\ndocument.getElementById('cancel-button').click(); // Simulate clicking the cancel button\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5F53\\u60A8\\u5355\\u51FB\\u201C\\u53D6\\u6D88\\u4E0A\\u4F20\\u201D\\u6309\\u94AE\\u65F6\\uFF0C\\u6B63\\u5728\\u8FDB\\u884C\\u7684\\u8BF7\\u6C42\\u5C06\\u88AB\\u4E2D\\u6B62\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5728\\u7ADE\\u4E89\\u6761\\u4EF6\\u4E0B\\u4F18\\u5148\\u5904\\u7406\\u6700\\u65B0\\u8BF7\\u6C42\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u4E3A\\u76F8\\u540C\\u6570\\u636E\\u542F\\u52A8\\u591A\\u4E2A\\u8BF7\\u6C42\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u4F18\\u5148\\u5904\\u7406\\u6700\\u65B0\\u8BF7\\u6C42\\u5E76\\u4E2D\\u6B62\\u8F83\\u65E9\\u7684\\u8BF7\\u6C42\\u3002\"]}),`\n`,(0,e.jsx)(n.pre,{live:!0,children:(0,e.jsx)(n.code,{className:\"language-js\",children:`let latestController = null; // Keeps track of the latest controller\n\nfunction fetchData(url) {\n if (latestController) {\n latestController.abort(); // Abort any previous request\n }\n\n const controller = new AbortController();\n latestController = controller;\n const signal = controller.signal;\n\n fetch(url, { signal })\n .then((response) => response.json())\n .then((data) => console.log('Fetched data:', data))\n .catch((error) => {\n if (error.name === 'AbortError') {\n console.log('Request canceled');\n } else {\n console.error('Network or other error:', error);\n }\n });\n}\n\nfetchData('https://jsonplaceholder.typicode.com/posts/1');\n\n// Simulate race conditions with new requests that quickly cancel the previous one\nsetTimeout(() => {\n fetchData('https://jsonplaceholder.typicode.com/posts/2');\n}, 5);\nsetTimeout(() => {\n fetchData('https://jsonplaceholder.typicode.com/posts/3');\n}, 5);\n// Only the last request should (posts/3) will be allowed to complete\n`})}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728\\u672C\\u4F8B\\u4E2D\\uFF0C\\u5F53\\u591A\\u6B21\\u8C03\\u7528 \",(0,e.jsx)(n.code,{children:\"fetchData()\"}),\" \\u51FD\\u6570\\u89E6\\u53D1\\u591A\\u4E2A fetch \\u8BF7\\u6C42\\u65F6\\uFF0C\",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u5C06\\u53D6\\u6D88\\u6240\\u6709\\u4E4B\\u524D\\u7684\\u8BF7\\u6C42\\uFF0C\\u9664\\u4E86\\u6700\\u65B0\\u7684\\u8BF7\\u6C42\\u3002\\u8FD9\\u5728\\u8BF8\\u5982\\u7C7B\\u578B\\u63D0\\u793A\\u641C\\u7D22\\u6216\\u65E0\\u9650\\u6EDA\\u52A8\\u7B49\\u573A\\u666F\\u4E2D\\u5F88\\u5E38\\u89C1\\uFF0C\\u5728\\u8FD9\\u4E9B\\u573A\\u666F\\u4E2D\\uFF0C\\u4F1A\\u9891\\u7E41\\u89E6\\u53D1\\u65B0\\u7684\\u8BF7\\u6C42\\u3002\"]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u53D6\\u6D88\\u4E0D\\u518D\\u9700\\u8981\\u7684\\u8BF7\\u6C42\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5728\\u7528\\u6237\\u5DF2\\u4ECE\\u9875\\u9762\\u5BFC\\u822A\\u51FA\\u53BB\\u7684\\u60C5\\u51B5\\u4E0B\\uFF0C\\u4E2D\\u6B62\\u8BF7\\u6C42\\u53EF\\u4EE5\\u9632\\u6B62\\u4E0D\\u5FC5\\u8981\\u7684\\u64CD\\u4F5C\\uFF08\\u4F8B\\u5982\\uFF0C\\u6210\\u529F\\u56DE\\u8C03\\u5904\\u7406\\uFF09\\uFF0C\\u5E76\\u901A\\u8FC7\\u964D\\u4F4E\\u5185\\u5B58\\u6CC4\\u6F0F\\u7684\\u53EF\\u80FD\\u6027\\u6765\\u91CA\\u653E\\u8D44\\u6E90\\u3002\"}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u7B14\\u8BB0\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u4E0D\\u4EC5\\u9650\\u4E8E \",(0,e.jsx)(n.code,{children:\"fetch()\"}),\"\\uFF0C\\u5B83\\u4E5F\\u53EF\\u4EE5\\u7528\\u4E8E\\u4E2D\\u6B62\\u5176\\u4ED6\\u5F02\\u6B65\\u4EFB\\u52A1\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u4E00\\u4E2A\\u5355\\u72EC\\u7684 \",(0,e.jsx)(n.code,{children:\"AbortContoller\"}),\" \\u5B9E\\u4F8B\\u53EF\\u4EE5\\u5728\\u591A\\u4E2A\\u5F02\\u6B65\\u4EFB\\u52A1\\u4E0A\\u91CD\\u590D\\u4F7F\\u7528\\uFF0C\\u5E76\\u4E00\\u6B21\\u53D6\\u6D88\\u6240\\u6709\\u4EFB\\u52A1\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[\"\\u5728 \",(0,e.jsx)(n.code,{children:\"AbortController\"}),\" \\u4E0A\\u8C03\\u7528 \",(0,e.jsx)(n.code,{children:\"abort()\"}),\" \\u4E0D\\u4F1A\\u5411\\u670D\\u52A1\\u5668\\u53D1\\u9001\\u4EFB\\u4F55\\u901A\\u77E5\\u6216\\u4FE1\\u53F7\\u3002\\u670D\\u52A1\\u5668\\u4E0D\\u77E5\\u9053\\u53D6\\u6D88\\u64CD\\u4F5C\\uFF0C\\u5E76\\u5C06\\u7EE7\\u7EED\\u5904\\u7406\\u8BF7\\u6C42\\uFF0C\\u76F4\\u5230\\u5B83\\u5B8C\\u6210\\u6216\\u8D85\\u65F6\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/AbortController\",children:\"AbortController | MDN\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/fetch-abort\",children:\"Fetch: Abort | Javascript.info\"})}),`\n`]})]})}function y(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(h,r)})):h(r)}var v=y;return A(w);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-debug-react-applications/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-do-you-debug-react-applications/locales/en-US.json
index b81ed8eb8..a53905a5a 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-debug-react-applications/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-debug-react-applications/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How do you debug React applications?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/how-do-you-debug-react-applications/en-US.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var y=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),b=(r,e)=>{for(var o in e)a(r,o,{get:e[o],enumerable:!0})},i=(r,e,o,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of u(e))!m.call(r,t)&&t!==o&&a(r,t,{get:()=>e[t],enumerable:!(c=p(e,t))||c.enumerable});return r};var f=(r,e,o)=>(o=r!=null?h(g(r)):{},i(e||!r||!r.__esModule?a(o,\"default\",{value:r,enumerable:!0}):o,r)),v=r=>i(a({},\"__esModule\",{value:!0}),r);var l=y((B,s)=>{s.exports=_jsx_runtime});var x={};b(x,{default:()=>C,frontmatter:()=>w});var n=f(l()),w={title:\"How do you debug React applications?\"};function d(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\",pre:\"pre\",ol:\"ol\",h4:\"h4\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"To debug React applications, you can use the React Developer Tools browser extension to inspect component hierarchies and state. Additionally, you can use \",(0,n.jsx)(e.code,{children:\"console.log\"}),\" statements to log data and errors, and leverage breakpoints in your code using browser developer tools. For more advanced debugging, you can use error boundaries to catch and handle errors in your components.\"]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"How do you debug React applications?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Using React Developer Tools\"}),`\n`,(0,n.jsx)(e.p,{children:\"The React Developer Tools browser extension is a powerful tool for inspecting and debugging React applications. It allows you to:\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Inspect the component hierarchy\"}),`\n`,(0,n.jsx)(e.li,{children:\"View and edit component state and props\"}),`\n`,(0,n.jsx)(e.li,{children:\"Trace component re-renders\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"You can install the extension from the \",(0,n.jsx)(e.a,{href:\"https://chrome.google.com/webstore/detail/react-developer-tools\",children:\"Chrome Web Store\"}),\" or \",(0,n.jsx)(e.a,{href:\"https://addons.mozilla.org/en-US/firefox/addon/react-devtools/\",children:\"Firefox Add-ons\"}),\".\"]}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"console.log\"}),\" statements\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Adding \",(0,n.jsx)(e.code,{children:\"console.log\"}),\" statements in your code can help you understand the flow of your application and identify issues. For example:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`function MyComponent(props) {\n console.log('Rendering MyComponent with props:', props);\n return {props.message}
;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Using breakpoints\"}),`\n`,(0,n.jsx)(e.p,{children:\"Browser developer tools, such as Chrome DevTools, allow you to set breakpoints in your code. This can help you pause execution and inspect the current state of your application. To set a breakpoint:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"Open the browser's developer tools (usually by pressing \",(0,n.jsx)(e.code,{children:\"F12\"}),\" or \",(0,n.jsx)(e.code,{children:\"Ctrl+Shift+I\"}),\").\"]}),`\n`,(0,n.jsx)(e.li,{children:'Navigate to the \"Sources\" tab.'}),`\n`,(0,n.jsx)(e.li,{children:\"Find the relevant file and line of code.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Click on the line number to set a breakpoint.\"}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Using Error Boundaries\"}),`\n`,(0,n.jsx)(e.p,{children:\"Error boundaries are React components that catch JavaScript errors in their child component tree. You can implement error boundaries in two ways:\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Using React's Built-in Class Component\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`class ErrorBoundary extends React.Component {\n constructor(props) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError(error) {\n // Update state so the next render will show the fallback UI.\n return { hasError: true };\n }\n\n componentDidCatch(error, info) {\n // You can also log the error to an error reporting service\n console.error('Error caught by error boundary:', error, info);\n }\n\n render() {\n if (this.state.hasError) {\n // You can render any custom fallback UI\n return Something went wrong. ;\n }\n\n return this.props.children;\n }\n}\n\n// Usage\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,n.jsx)(e.h4,{children:\"Using react-error-boundary Package\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Alternatively, you can use the \",(0,n.jsx)(e.code,{children:\"react-error-boundary\"}),\" package for a more convenient approach:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import { ErrorBoundary } from 'react-error-boundary';\n\nfunction ErrorFallback({ error, resetErrorBoundary }) {\n return (\n \n
Something went wrong:
\n
{error.message} \n
Try again \n
\n );\n}\n\nfunction App() {\n return (\n {\n // Reset the state of your app\n }}\n onError={(error, info) => {\n // Log the error to an error reporting service\n }}\n >\n \n \n );\n}\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"For handling errors in event handlers or async code, you can use the \",(0,n.jsx)(e.code,{children:\"useErrorBoundary\"}),\" hook:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import { useErrorBoundary } from 'react-error-boundary';\n\nfunction MyComponent() {\n const { showBoundary } = useErrorBoundary();\n\n const handleAsyncError = async () => {\n try {\n await someAsyncOperation();\n } catch (error) {\n showBoundary(error);\n }\n };\n\n return Perform Action ;\n}\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/blog/2015/09/02/new-react-developer-tools.html\",children:\"React Developer Tools\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/error-boundaries.html\",children:\"Error boundaries in React\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developers.google.com/web/tools/chrome-devtools\",children:\"Using the Chrome DevTools\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Debugging\",children:\"Debugging JavaScript\"})}),`\n`]})]})}function E(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(d,r)})):d(r)}var C=E;return v(x);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var a=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var y=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),b=(r,e)=>{for(var o in e)a(r,o,{get:e[o],enumerable:!0})},i=(r,e,o,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let t of u(e))!m.call(r,t)&&t!==o&&a(r,t,{get:()=>e[t],enumerable:!(c=p(e,t))||c.enumerable});return r};var f=(r,e,o)=>(o=r!=null?h(g(r)):{},i(e||!r||!r.__esModule?a(o,\"default\",{value:r,enumerable:!0}):o,r)),v=r=>i(a({},\"__esModule\",{value:!0}),r);var l=y((B,s)=>{s.exports=_jsx_runtime});var x={};b(x,{default:()=>C,frontmatter:()=>w});var n=f(l()),w={title:\"How do you debug React applications?\"};function d(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\",pre:\"pre\",ol:\"ol\",h4:\"h4\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"To debug React applications, you can use the React Developer Tools browser extension to inspect component hierarchies and state. Additionally, you can use \",(0,n.jsx)(e.code,{children:\"console.log\"}),\" statements to log data and errors, and leverage breakpoints in your code using browser developer tools. For more advanced debugging, you can use error boundaries to catch and handle errors in your components.\"]}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"How do you debug React applications?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Using React Developer Tools\"}),`\n`,(0,n.jsx)(e.p,{children:\"The React Developer Tools browser extension is a powerful tool for inspecting and debugging React applications. It allows you to:\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"Inspect the component hierarchy\"}),`\n`,(0,n.jsx)(e.li,{children:\"View and edit component state and props\"}),`\n`,(0,n.jsx)(e.li,{children:\"Trace component re-renders\"}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"You can install the extension from the \",(0,n.jsx)(e.a,{href:\"https://chrome.google.com/webstore/detail/react-developer-tools\",children:\"Chrome Web Store\"}),\" or \",(0,n.jsx)(e.a,{href:\"https://addons.mozilla.org/en-US/firefox/addon/react-devtools/\",children:\"Firefox Add-ons\"}),\".\"]}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"console.log\"}),\" statements\"]}),`\n`,(0,n.jsxs)(e.p,{children:[\"Adding \",(0,n.jsx)(e.code,{children:\"console.log\"}),\" statements in your code can help you understand the flow of your application and identify issues. For example:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`function MyComponent(props) {\n console.log('Rendering MyComponent with props:', props);\n return {props.message}
;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Using breakpoints\"}),`\n`,(0,n.jsx)(e.p,{children:\"Browser developer tools, such as Chrome DevTools, allow you to set breakpoints in your code. This can help you pause execution and inspect the current state of your application. To set a breakpoint:\"}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[\"Open the browser's developer tools (usually by pressing \",(0,n.jsx)(e.code,{children:\"F12\"}),\" or \",(0,n.jsx)(e.code,{children:\"Ctrl+Shift+I\"}),\").\"]}),`\n`,(0,n.jsx)(e.li,{children:'Navigate to the \"Sources\" tab.'}),`\n`,(0,n.jsx)(e.li,{children:\"Find the relevant file and line of code.\"}),`\n`,(0,n.jsx)(e.li,{children:\"Click on the line number to set a breakpoint.\"}),`\n`]}),`\n`,(0,n.jsx)(e.h3,{children:\"Using Error Boundaries\"}),`\n`,(0,n.jsx)(e.p,{children:\"Error boundaries are React components that catch JavaScript errors in their child component tree. You can implement error boundaries in two ways:\"}),`\n`,(0,n.jsx)(e.h4,{children:\"Using React's Built-in Class Component\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`class ErrorBoundary extends React.Component {\n constructor(props) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError(error) {\n // Update state so the next render will show the fallback UI.\n return { hasError: true };\n }\n\n componentDidCatch(error, info) {\n // You can also log the error to an error reporting service\n console.error('Error caught by error boundary:', error, info);\n }\n\n render() {\n if (this.state.hasError) {\n // You can render any custom fallback UI\n return Something went wrong. ;\n }\n\n return this.props.children;\n }\n}\n\n// Usage\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,n.jsx)(e.h4,{children:\"Using react-error-boundary Package\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"Alternatively, you can use the \",(0,n.jsx)(e.code,{children:\"react-error-boundary\"}),\" package for a more convenient approach:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import { ErrorBoundary } from 'react-error-boundary';\n\nfunction ErrorFallback({ error, resetErrorBoundary }) {\n return (\n \n
Something went wrong:
\n
{error.message} \n
Try again \n
\n );\n}\n\nfunction App() {\n return (\n {\n // Reset the state of your app\n }}\n onError={(error, info) => {\n // Log the error to an error reporting service\n }}\n >\n \n \n );\n}\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"For handling errors in event handlers or async code, you can use the \",(0,n.jsx)(e.code,{children:\"useErrorBoundary\"}),\" hook:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import { useErrorBoundary } from 'react-error-boundary';\n\nfunction MyComponent() {\n const { showBoundary } = useErrorBoundary();\n\n const handleAsyncError = async () => {\n try {\n await someAsyncOperation();\n } catch (error) {\n showBoundary(error);\n }\n };\n\n return Perform Action ;\n}\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn/react-developer-tools\",children:\"React Developer Tools\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary\",children:\"Error boundaries in React\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developers.google.com/web/tools/chrome-devtools\",children:\"Using the Chrome DevTools\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Debugging\",children:\"Debugging JavaScript\"})}),`\n`]})]})}function E(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(d,r)})):d(r)}var C=E;return v(x);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-debug-react-applications/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/how-do-you-debug-react-applications/locales/zh-CN.json
index 20c0f6dfa..97927a4f9 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-debug-react-applications/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-debug-react-applications/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "如何调试 React 应用程序?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/how-do-you-debug-react-applications/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var s=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var y=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),f=(e,r)=>{for(var o in r)c(e,o,{get:r[o],enumerable:!0})},a=(e,r,o,l)=>{if(r&&typeof r==\"object\"||typeof r==\"function\")for(let t of u(r))!g.call(e,t)&&t!==o&&c(e,t,{get:()=>r[t],enumerable:!(l=p(r,t))||l.enumerable});return e};var v=(e,r,o)=>(o=e!=null?s(m(e)):{},a(r||!e||!e.__esModule?c(o,\"default\",{value:e,enumerable:!0}):o,e)),b=e=>a(c({},\"__esModule\",{value:!0}),e);var d=y((B,i)=>{i.exports=_jsx_runtime});var j={};f(j,{default:()=>R,frontmatter:()=>E});var n=v(d()),E={title:\"\\u5982\\u4F55\\u8C03\\u8BD5 React \\u5E94\\u7528\\u7A0B\\u5E8F\\uFF1F\"};function h(e){let r=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\",pre:\"pre\",ol:\"ol\",h4:\"h4\"},e.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u8981\\u8C03\\u8BD5 React \\u5E94\\u7528\\u7A0B\\u5E8F\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 React Developer Tools \\u6D4F\\u89C8\\u5668\\u6269\\u5C55\\u7A0B\\u5E8F\\u6765\\u68C0\\u67E5\\u7EC4\\u4EF6\\u5C42\\u6B21\\u7ED3\\u6784\\u548C\\u72B6\\u6001\\u3002\\u6B64\\u5916\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(r.code,{children:\"console.log\"}),\" \\u8BED\\u53E5\\u6765\\u8BB0\\u5F55\\u6570\\u636E\\u548C\\u9519\\u8BEF\\uFF0C\\u5E76\\u5229\\u7528\\u6D4F\\u89C8\\u5668\\u5F00\\u53D1\\u8005\\u5DE5\\u5177\\u5728\\u4EE3\\u7801\\u4E2D\\u8BBE\\u7F6E\\u65AD\\u70B9\\u3002\\u5BF9\\u4E8E\\u66F4\\u9AD8\\u7EA7\\u7684\\u8C03\\u8BD5\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528\\u9519\\u8BEF\\u8FB9\\u754C\\u6765\\u6355\\u83B7\\u548C\\u5904\\u7406\\u7EC4\\u4EF6\\u4E2D\\u7684\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,n.jsx)(r.hr,{}),`\n`,(0,n.jsx)(r.h2,{children:\"\\u5982\\u4F55\\u8C03\\u8BD5 React \\u5E94\\u7528\\u7A0B\\u5E8F\\uFF1F\"}),`\n`,(0,n.jsx)(r.h3,{children:\"\\u4F7F\\u7528 React Developer Tools\"}),`\n`,(0,n.jsx)(r.p,{children:\"React Developer Tools \\u6D4F\\u89C8\\u5668\\u6269\\u5C55\\u7A0B\\u5E8F\\u662F\\u4E00\\u4E2A\\u7528\\u4E8E\\u68C0\\u67E5\\u548C\\u8C03\\u8BD5 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u5F3A\\u5927\\u5DE5\\u5177\\u3002\\u5B83\\u5141\\u8BB8\\u60A8\\uFF1A\"}),`\n`,(0,n.jsxs)(r.ul,{children:[`\n`,(0,n.jsx)(r.li,{children:\"\\u68C0\\u67E5\\u7EC4\\u4EF6\\u5C42\\u6B21\\u7ED3\\u6784\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u67E5\\u770B\\u548C\\u7F16\\u8F91\\u7EC4\\u4EF6\\u72B6\\u6001\\u548C\\u5C5E\\u6027\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u8DDF\\u8E2A\\u7EC4\\u4EF6\\u91CD\\u65B0\\u6E32\\u67D3\"}),`\n`]}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u60A8\\u53EF\\u4EE5\\u4ECE \",(0,n.jsx)(r.a,{href:\"https://chrome.google.com/webstore/detail/react-developer-tools\",children:\"Chrome Web Store\"}),\" \\u6216 \",(0,n.jsx)(r.a,{href:\"https://addons.mozilla.org/en-US/firefox/addon/react-devtools/\",children:\"Firefox Add-ons\"}),\" \\u5B89\\u88C5\\u8BE5\\u6269\\u5C55\\u7A0B\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(r.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(r.code,{children:\"console.log\"}),\" \\u8BED\\u53E5\"]}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u5728\\u4EE3\\u7801\\u4E2D\\u6DFB\\u52A0 \",(0,n.jsx)(r.code,{children:\"console.log\"}),\" \\u8BED\\u53E5\\u53EF\\u4EE5\\u5E2E\\u52A9\\u60A8\\u4E86\\u89E3\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u6D41\\u7A0B\\u5E76\\u8BC6\\u522B\\u95EE\\u9898\\u3002\\u4F8B\\u5982\\uFF1A\"]}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-javascript\",children:`function MyComponent(props) {\n console.log('Rendering MyComponent with props:', props);\n return {props.message}
;\n}\n`})}),`\n`,(0,n.jsx)(r.h3,{children:\"\\u4F7F\\u7528\\u65AD\\u70B9\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u6D4F\\u89C8\\u5668\\u5F00\\u53D1\\u8005\\u5DE5\\u5177\\uFF08\\u4F8B\\u5982 Chrome DevTools\\uFF09\\u5141\\u8BB8\\u60A8\\u5728\\u4EE3\\u7801\\u4E2D\\u8BBE\\u7F6E\\u65AD\\u70B9\\u3002\\u8FD9\\u53EF\\u4EE5\\u5E2E\\u52A9\\u60A8\\u6682\\u505C\\u6267\\u884C\\u5E76\\u68C0\\u67E5\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u5F53\\u524D\\u72B6\\u6001\\u3002\\u8981\\u8BBE\\u7F6E\\u65AD\\u70B9\\uFF1A\"}),`\n`,(0,n.jsxs)(r.ol,{children:[`\n`,(0,n.jsxs)(r.li,{children:[\"\\u6253\\u5F00\\u6D4F\\u89C8\\u5668\\u7684\\u5F00\\u53D1\\u8005\\u5DE5\\u5177\\uFF08\\u901A\\u5E38\\u6309 \",(0,n.jsx)(r.code,{children:\"F12\"}),\" \\u6216 \",(0,n.jsx)(r.code,{children:\"Ctrl+Shift+I\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,n.jsx)(r.li,{children:\"\\u5BFC\\u822A\\u5230\\u201CSources\\u201D\\u9009\\u9879\\u5361\\u3002\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u627E\\u5230\\u76F8\\u5173\\u6587\\u4EF6\\u548C\\u4EE3\\u7801\\u884C\\u3002\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u5355\\u51FB\\u884C\\u53F7\\u4EE5\\u8BBE\\u7F6E\\u65AD\\u70B9\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(r.h3,{children:\"\\u4F7F\\u7528\\u9519\\u8BEF\\u8FB9\\u754C\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u9519\\u8BEF\\u8FB9\\u754C\\u662F React \\u7EC4\\u4EF6\\uFF0C\\u7528\\u4E8E\\u6355\\u83B7\\u5176\\u5B50\\u7EC4\\u4EF6\\u6811\\u4E2D\\u7684 JavaScript \\u9519\\u8BEF\\u3002\\u60A8\\u53EF\\u4EE5\\u901A\\u8FC7\\u4E24\\u79CD\\u65B9\\u5F0F\\u5B9E\\u73B0\\u9519\\u8BEF\\u8FB9\\u754C\\uFF1A\"}),`\n`,(0,n.jsx)(r.h4,{children:\"\\u4F7F\\u7528 React \\u7684\\u5185\\u7F6E\\u7C7B\\u7EC4\\u4EF6\"}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-javascript\",children:`class ErrorBoundary extends React.Component {\n constructor(props) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError(error) {\n // Update state so the next render will show the fallback UI.\n return { hasError: true };\n }\n\n componentDidCatch(error, info) {\n // You can also log the error to an error reporting service\n console.error('Error caught by error boundary:', error, info);\n }\n\n render() {\n if (this.state.hasError) {\n // You can render any custom fallback UI\n return Something went wrong. ;\n }\n\n return this.props.children;\n }\n}\n\n// Usage\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,n.jsx)(r.h4,{children:\"\\u4F7F\\u7528 react-error-boundary \\u5305\"}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u6216\\u8005\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(r.code,{children:\"react-error-boundary\"}),\" \\u5305\\u6765\\u83B7\\u5F97\\u66F4\\u65B9\\u4FBF\\u7684\\u65B9\\u6CD5\\uFF1A\"]}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-javascript\",children:`import { ErrorBoundary } from 'react-error-boundary';\n\nfunction ErrorFallback({ error, resetErrorBoundary }) {\n return (\n \n
\\u51FA\\u9519\\u4E86\\uFF1A
\n
{error.message} \n
\\u91CD\\u8BD5 \n
\n );\n}\n\nfunction App() {\n return (\n {\n // \\u91CD\\u7F6E\\u60A8\\u7684\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u72B6\\u6001\n }}\n onError={(error, info) => {\n // \\u5C06\\u9519\\u8BEF\\u8BB0\\u5F55\\u5230\\u9519\\u8BEF\\u62A5\\u544A\\u670D\\u52A1\n }}\n >\n \n \n );\n}\n`})}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u5BF9\\u4E8E\\u5904\\u7406\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\u6216\\u5F02\\u6B65\\u4EE3\\u7801\\u4E2D\\u7684\\u9519\\u8BEF\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(r.code,{children:\"useErrorBoundary\"}),\" \\u94A9\\u5B50\\uFF1A\"]}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-javascript\",children:`import { useErrorBoundary } from 'react-error-boundary';\n\nfunction MyComponent() {\n const { showBoundary } = useErrorBoundary();\n\n const handleAsyncError = async () => {\n try {\n await someAsyncOperation();\n } catch (error) {\n showBoundary(error);\n }\n };\n\n return \\u6267\\u884C\\u64CD\\u4F5C ;\n}\n`})}),`\n`,(0,n.jsx)(r.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(r.ul,{children:[`\n`,(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:\"https://reactjs.org/blog/2015/09/02/new-react-developer-tools.html\",children:\"React \\u5F00\\u53D1\\u8005\\u5DE5\\u5177\"})}),`\n`,(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:\"https://reactjs.org/docs/error-boundaries.html\",children:\"React \\u4E2D\\u7684\\u9519\\u8BEF\\u8FB9\\u754C\"})}),`\n`,(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:\"https://developers.google.com/web/tools/chrome-devtools\",children:\"\\u4F7F\\u7528 Chrome DevTools\"})}),`\n`,(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Debugging\",children:\"\\u8C03\\u8BD5 JavaScript\"})}),`\n`]})]})}function C(e={}){let{wrapper:r}=e.components||{};return r?(0,n.jsx)(r,Object.assign({},e,{children:(0,n.jsx)(h,e)})):h(e)}var R=C;return b(j);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var y=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),f=(e,r)=>{for(var o in r)c(e,o,{get:r[o],enumerable:!0})},a=(e,r,o,l)=>{if(r&&typeof r==\"object\"||typeof r==\"function\")for(let t of u(r))!m.call(e,t)&&t!==o&&c(e,t,{get:()=>r[t],enumerable:!(l=p(r,t))||l.enumerable});return e};var v=(e,r,o)=>(o=e!=null?s(g(e)):{},a(r||!e||!e.__esModule?c(o,\"default\",{value:e,enumerable:!0}):o,e)),b=e=>a(c({},\"__esModule\",{value:!0}),e);var d=y((D,i)=>{i.exports=_jsx_runtime});var x={};f(x,{default:()=>R,frontmatter:()=>E});var n=v(d()),E={title:\"\\u5982\\u4F55\\u8C03\\u8BD5 React \\u5E94\\u7528\\u7A0B\\u5E8F\\uFF1F\"};function h(e){let r=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\",pre:\"pre\",ol:\"ol\",h4:\"h4\"},e.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u8981\\u8C03\\u8BD5 React \\u5E94\\u7528\\u7A0B\\u5E8F\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 React Developer Tools \\u6D4F\\u89C8\\u5668\\u6269\\u5C55\\u7A0B\\u5E8F\\u6765\\u68C0\\u67E5\\u7EC4\\u4EF6\\u5C42\\u6B21\\u7ED3\\u6784\\u548C\\u72B6\\u6001\\u3002\\u6B64\\u5916\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(r.code,{children:\"console.log\"}),\" \\u8BED\\u53E5\\u6765\\u8BB0\\u5F55\\u6570\\u636E\\u548C\\u9519\\u8BEF\\uFF0C\\u5E76\\u5229\\u7528\\u6D4F\\u89C8\\u5668\\u5F00\\u53D1\\u8005\\u5DE5\\u5177\\u5728\\u4EE3\\u7801\\u4E2D\\u8BBE\\u7F6E\\u65AD\\u70B9\\u3002\\u5BF9\\u4E8E\\u66F4\\u9AD8\\u7EA7\\u7684\\u8C03\\u8BD5\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528\\u9519\\u8BEF\\u8FB9\\u754C\\u6765\\u6355\\u83B7\\u548C\\u5904\\u7406\\u7EC4\\u4EF6\\u4E2D\\u7684\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,n.jsx)(r.hr,{}),`\n`,(0,n.jsx)(r.h2,{children:\"\\u5982\\u4F55\\u8C03\\u8BD5 React \\u5E94\\u7528\\u7A0B\\u5E8F\\uFF1F\"}),`\n`,(0,n.jsx)(r.h3,{children:\"\\u4F7F\\u7528 React Developer Tools\"}),`\n`,(0,n.jsx)(r.p,{children:\"React Developer Tools \\u6D4F\\u89C8\\u5668\\u6269\\u5C55\\u7A0B\\u5E8F\\u662F\\u4E00\\u4E2A\\u7528\\u4E8E\\u68C0\\u67E5\\u548C\\u8C03\\u8BD5 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u5F3A\\u5927\\u5DE5\\u5177\\u3002\\u5B83\\u5141\\u8BB8\\u60A8\\uFF1A\"}),`\n`,(0,n.jsxs)(r.ul,{children:[`\n`,(0,n.jsx)(r.li,{children:\"\\u68C0\\u67E5\\u7EC4\\u4EF6\\u5C42\\u6B21\\u7ED3\\u6784\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u67E5\\u770B\\u548C\\u7F16\\u8F91\\u7EC4\\u4EF6\\u72B6\\u6001\\u548C\\u5C5E\\u6027\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u8DDF\\u8E2A\\u7EC4\\u4EF6\\u91CD\\u65B0\\u6E32\\u67D3\"}),`\n`]}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u60A8\\u53EF\\u4EE5\\u4ECE \",(0,n.jsx)(r.a,{href:\"https://chrome.google.com/webstore/detail/react-developer-tools\",children:\"Chrome Web Store\"}),\" \\u6216 \",(0,n.jsx)(r.a,{href:\"https://addons.mozilla.org/en-US/firefox/addon/react-devtools/\",children:\"Firefox Add-ons\"}),\" \\u5B89\\u88C5\\u8BE5\\u6269\\u5C55\\u7A0B\\u5E8F\\u3002\"]}),`\n`,(0,n.jsxs)(r.h3,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(r.code,{children:\"console.log\"}),\" \\u8BED\\u53E5\"]}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u5728\\u4EE3\\u7801\\u4E2D\\u6DFB\\u52A0 \",(0,n.jsx)(r.code,{children:\"console.log\"}),\" \\u8BED\\u53E5\\u53EF\\u4EE5\\u5E2E\\u52A9\\u60A8\\u4E86\\u89E3\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u6D41\\u7A0B\\u5E76\\u8BC6\\u522B\\u95EE\\u9898\\u3002\\u4F8B\\u5982\\uFF1A\"]}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-javascript\",children:`function MyComponent(props) {\n console.log('Rendering MyComponent with props:', props);\n return {props.message}
;\n}\n`})}),`\n`,(0,n.jsx)(r.h3,{children:\"\\u4F7F\\u7528\\u65AD\\u70B9\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u6D4F\\u89C8\\u5668\\u5F00\\u53D1\\u8005\\u5DE5\\u5177\\uFF08\\u4F8B\\u5982 Chrome DevTools\\uFF09\\u5141\\u8BB8\\u60A8\\u5728\\u4EE3\\u7801\\u4E2D\\u8BBE\\u7F6E\\u65AD\\u70B9\\u3002\\u8FD9\\u53EF\\u4EE5\\u5E2E\\u52A9\\u60A8\\u6682\\u505C\\u6267\\u884C\\u5E76\\u68C0\\u67E5\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u5F53\\u524D\\u72B6\\u6001\\u3002\\u8981\\u8BBE\\u7F6E\\u65AD\\u70B9\\uFF1A\"}),`\n`,(0,n.jsxs)(r.ol,{children:[`\n`,(0,n.jsxs)(r.li,{children:[\"\\u6253\\u5F00\\u6D4F\\u89C8\\u5668\\u7684\\u5F00\\u53D1\\u8005\\u5DE5\\u5177\\uFF08\\u901A\\u5E38\\u6309 \",(0,n.jsx)(r.code,{children:\"F12\"}),\" \\u6216 \",(0,n.jsx)(r.code,{children:\"Ctrl+Shift+I\"}),\"\\uFF09\\u3002\"]}),`\n`,(0,n.jsx)(r.li,{children:\"\\u5BFC\\u822A\\u5230\\u201CSources\\u201D\\u9009\\u9879\\u5361\\u3002\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u627E\\u5230\\u76F8\\u5173\\u6587\\u4EF6\\u548C\\u4EE3\\u7801\\u884C\\u3002\"}),`\n`,(0,n.jsx)(r.li,{children:\"\\u5355\\u51FB\\u884C\\u53F7\\u4EE5\\u8BBE\\u7F6E\\u65AD\\u70B9\\u3002\"}),`\n`]}),`\n`,(0,n.jsx)(r.h3,{children:\"\\u4F7F\\u7528\\u9519\\u8BEF\\u8FB9\\u754C\"}),`\n`,(0,n.jsx)(r.p,{children:\"\\u9519\\u8BEF\\u8FB9\\u754C\\u662F React \\u7EC4\\u4EF6\\uFF0C\\u7528\\u4E8E\\u6355\\u83B7\\u5176\\u5B50\\u7EC4\\u4EF6\\u6811\\u4E2D\\u7684 JavaScript \\u9519\\u8BEF\\u3002\\u60A8\\u53EF\\u4EE5\\u901A\\u8FC7\\u4E24\\u79CD\\u65B9\\u5F0F\\u5B9E\\u73B0\\u9519\\u8BEF\\u8FB9\\u754C\\uFF1A\"}),`\n`,(0,n.jsx)(r.h4,{children:\"\\u4F7F\\u7528 React \\u7684\\u5185\\u7F6E\\u7C7B\\u7EC4\\u4EF6\"}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-javascript\",children:`class ErrorBoundary extends React.Component {\n constructor(props) {\n super(props);\n this.state = { hasError: false };\n }\n\n static getDerivedStateFromError(error) {\n // Update state so the next render will show the fallback UI.\n return { hasError: true };\n }\n\n componentDidCatch(error, info) {\n // You can also log the error to an error reporting service\n console.error('Error caught by error boundary:', error, info);\n }\n\n render() {\n if (this.state.hasError) {\n // You can render any custom fallback UI\n return Something went wrong. ;\n }\n\n return this.props.children;\n }\n}\n\n// Usage\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,n.jsx)(r.h4,{children:\"\\u4F7F\\u7528 react-error-boundary \\u5305\"}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u6216\\u8005\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(r.code,{children:\"react-error-boundary\"}),\" \\u5305\\u6765\\u83B7\\u5F97\\u66F4\\u65B9\\u4FBF\\u7684\\u65B9\\u6CD5\\uFF1A\"]}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-javascript\",children:`import { ErrorBoundary } from 'react-error-boundary';\n\nfunction ErrorFallback({ error, resetErrorBoundary }) {\n return (\n \n
\\u51FA\\u9519\\u4E86\\uFF1A
\n
{error.message} \n
\\u91CD\\u8BD5 \n
\n );\n}\n\nfunction App() {\n return (\n {\n // \\u91CD\\u7F6E\\u60A8\\u7684\\u5E94\\u7528\\u7A0B\\u5E8F\\u7684\\u72B6\\u6001\n }}\n onError={(error, info) => {\n // \\u5C06\\u9519\\u8BEF\\u8BB0\\u5F55\\u5230\\u9519\\u8BEF\\u62A5\\u544A\\u670D\\u52A1\n }}\n >\n \n \n );\n}\n`})}),`\n`,(0,n.jsxs)(r.p,{children:[\"\\u5BF9\\u4E8E\\u5904\\u7406\\u4E8B\\u4EF6\\u5904\\u7406\\u7A0B\\u5E8F\\u6216\\u5F02\\u6B65\\u4EE3\\u7801\\u4E2D\\u7684\\u9519\\u8BEF\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(r.code,{children:\"useErrorBoundary\"}),\" \\u94A9\\u5B50\\uFF1A\"]}),`\n`,(0,n.jsx)(r.pre,{children:(0,n.jsx)(r.code,{className:\"language-javascript\",children:`import { useErrorBoundary } from 'react-error-boundary';\n\nfunction MyComponent() {\n const { showBoundary } = useErrorBoundary();\n\n const handleAsyncError = async () => {\n try {\n await someAsyncOperation();\n } catch (error) {\n showBoundary(error);\n }\n };\n\n return \\u6267\\u884C\\u64CD\\u4F5C ;\n}\n`})}),`\n`,(0,n.jsx)(r.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(r.ul,{children:[`\n`,(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:\"https://react.dev/learn/react-developer-tools\",children:\"React Developer Tools\"})}),`\n`,(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:\"https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary\",children:\"Error boundaries in React\"})}),`\n`,(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:\"https://developers.google.com/web/tools/chrome-devtools\",children:\"Using the Chrome DevTools\"})}),`\n`,(0,n.jsx)(r.li,{children:(0,n.jsx)(r.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/First_steps/Debugging\",children:\"Debugging JavaScript\"})}),`\n`]})]})}function C(e={}){let{wrapper:r}=e.components||{};return r?(0,n.jsx)(r,Object.assign({},e,{children:(0,n.jsx)(h,e)})):h(e)}var R=C;return b(x);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-decide-between-using-react-state-context-and-external-state-managers/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-do-you-decide-between-using-react-state-context-and-external-state-managers/locales/en-US.json
index 3d149775e..ee1157822 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-decide-between-using-react-state-context-and-external-state-managers/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-decide-between-using-react-state-context-and-external-state-managers/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How do you decide between using React state, context, and external state managers?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/how-do-you-decide-between-using-react-state-context-and-external-state-managers/en-US.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var x=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),f=(t,e)=>{for(var o in e)a(t,o,{get:e[o],enumerable:!0})},c=(t,e,o,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of m(e))!g.call(t,r)&&r!==o&&a(t,r,{get:()=>e[r],enumerable:!(s=u(e,r))||s.enumerable});return t};var v=(t,e,o)=>(o=t!=null?h(p(t)):{},c(e||!t||!t.__esModule?a(o,\"default\",{value:t,enumerable:!0}):o,t)),b=t=>c(a({},\"__esModule\",{value:!0}),t);var d=x((T,i)=>{i.exports=_jsx_runtime});var j={};f(j,{default:()=>y,frontmatter:()=>C});var n=v(d()),C={title:\"How do you decide between using React state, context, and external state managers?\"};function l(t){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",pre:\"pre\",code:\"code\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"Choosing between React state, context, and external state managers depends on the complexity and scope of your application's state management needs. Use React state for local component state, React context for global state that needs to be shared across multiple components, and external state managers like Redux or MobX for complex state management that requires advanced features like middleware, time-travel debugging, or when the state needs to be shared across a large application.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Deciding between React state, context, and external state managers\"}),`\n`,(0,n.jsx)(e.h3,{children:\"React state\"}),`\n`,(0,n.jsx)(e.p,{children:\"React state is best suited for managing local state within a single component. It is simple to use and provides a straightforward way to handle state that does not need to be shared across multiple components.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"When to use React state\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"When the state is only relevant to a single component\"}),`\n`,(0,n.jsx)(e.li,{children:\"When the state does not need to be accessed or modified by other components\"}),`\n`,(0,n.jsx)(e.li,{children:\"When you want to keep the component self-contained and easy to understand\"}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Example\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`import React, { useState } from 'react';\n\nfunction Counter() {\n const [count, setCount] = useState(0);\n\n return (\n \n
Count: {count}
\n
setCount(count + 1)}>Increment \n
\n );\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"React context\"}),`\n`,(0,n.jsx)(e.p,{children:\"React context is useful for sharing state across multiple components without having to pass props down through every level of the component tree. It is ideal for global state that needs to be accessed by many components.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"When to use React context\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"When you need to share state across multiple components\"}),`\n`,(0,n.jsx)(e.li,{children:\"When you want to avoid prop drilling (passing props through many levels of components)\"}),`\n`,(0,n.jsx)(e.li,{children:\"When the state is relatively simple and does not require advanced state management features\"}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Example\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`import React, { createContext, useContext, useState } from 'react';\n\nconst ThemeContext = createContext();\n\nfunction ThemeProvider({ children }) {\n const [theme, setTheme] = useState('light');\n\n return (\n \n {children}\n \n );\n}\n\nfunction ThemedComponent() {\n const { theme, setTheme } = useContext(ThemeContext);\n\n return (\n \n
Current theme: {theme}
\n
setTheme(theme === 'light' ? 'dark' : 'light')}>\n Toggle Theme\n \n
\n );\n}\n\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"External state managers\"}),`\n`,(0,n.jsx)(e.p,{children:\"External state managers like Redux or MobX are designed for complex state management needs. They provide advanced features such as middleware, time-travel debugging, and the ability to manage state across a large application.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"When to use external state managers\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"When the state management needs are complex and involve many interconnected pieces of state\"}),`\n`,(0,n.jsx)(e.li,{children:\"When you need advanced features like middleware, time-travel debugging, or dev tools\"}),`\n`,(0,n.jsx)(e.li,{children:\"When the state needs to be shared across a large application with many components\"}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Example with Redux\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`// actions.js\nexport const increment = () => ({ type: 'INCREMENT' });\n\n// reducer.js\nconst initialState = { count: 0 };\n\nfunction counterReducer(state = initialState, action) {\n switch (action.type) {\n case 'INCREMENT':\n return { ...state, count: state.count + 1 };\n default:\n return state;\n }\n}\n\nexport default counterReducer;\n\n// store.js\nimport { createStore } from 'redux';\nimport counterReducer from './reducer';\n\nconst store = createStore(counterReducer);\n\nexport default store;\n\n// Counter.js\nimport React from 'react';\nimport { useSelector, useDispatch } from 'react-redux';\nimport { increment } from './actions';\n\nfunction Counter() {\n const count = useSelector((state) => state.count);\n const dispatch = useDispatch();\n\n return (\n \n
Count: {count}
\n
dispatch(increment())}>Increment \n
\n );\n}\n\n// App.js\nimport React from 'react';\nimport { Provider } from 'react-redux';\nimport store from './store';\nimport Counter from './Counter';\n\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/state-and-lifecycle.html\",children:\"React documentation on state\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/context.html\",children:\"React documentation on context\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://redux.js.org/\",children:\"Redux documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://mobx.js.org/README.html\",children:\"MobX documentation\"})}),`\n`]})]})}function R(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var y=R;return b(j);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var x=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),f=(t,e)=>{for(var o in e)a(t,o,{get:e[o],enumerable:!0})},c=(t,e,o,s)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of u(e))!g.call(t,r)&&r!==o&&a(t,r,{get:()=>e[r],enumerable:!(s=m(e,r))||s.enumerable});return t};var v=(t,e,o)=>(o=t!=null?h(p(t)):{},c(e||!t||!t.__esModule?a(o,\"default\",{value:t,enumerable:!0}):o,t)),b=t=>c(a({},\"__esModule\",{value:!0}),t);var d=x((j,i)=>{i.exports=_jsx_runtime});var w={};f(w,{default:()=>y,frontmatter:()=>C});var n=v(d()),C={title:\"How do you decide between using React state, context, and external state managers?\"};function l(t){let e=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",pre:\"pre\",code:\"code\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsx)(e.p,{children:\"Choosing between React state, context, and external state managers depends on the complexity and scope of your application's state management needs. Use React state for local component state, React context for global state that needs to be shared across multiple components, and external state managers like Redux or MobX for complex state management that requires advanced features like middleware, time-travel debugging, or when the state needs to be shared across a large application.\"}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Deciding between React state, context, and external state managers\"}),`\n`,(0,n.jsx)(e.h3,{children:\"React state\"}),`\n`,(0,n.jsx)(e.p,{children:\"React state is best suited for managing local state within a single component. It is simple to use and provides a straightforward way to handle state that does not need to be shared across multiple components.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"When to use React state\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"When the state is only relevant to a single component\"}),`\n`,(0,n.jsx)(e.li,{children:\"When the state does not need to be accessed or modified by other components\"}),`\n`,(0,n.jsx)(e.li,{children:\"When you want to keep the component self-contained and easy to understand\"}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Example\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`import React, { useState } from 'react';\n\nfunction Counter() {\n const [count, setCount] = useState(0);\n\n return (\n \n
Count: {count}
\n
setCount(count + 1)}>Increment \n
\n );\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"React context\"}),`\n`,(0,n.jsx)(e.p,{children:\"React context is useful for sharing state across multiple components without having to pass props down through every level of the component tree. It is ideal for global state that needs to be accessed by many components.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"When to use React context\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"When you need to share state across multiple components\"}),`\n`,(0,n.jsx)(e.li,{children:\"When you want to avoid prop drilling (passing props through many levels of components)\"}),`\n`,(0,n.jsx)(e.li,{children:\"When the state is relatively simple and does not require advanced state management features\"}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Example\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`import React, { createContext, useContext, useState } from 'react';\n\nconst ThemeContext = createContext();\n\nfunction ThemeProvider({ children }) {\n const [theme, setTheme] = useState('light');\n\n return (\n \n {children}\n \n );\n}\n\nfunction ThemedComponent() {\n const { theme, setTheme } = useContext(ThemeContext);\n\n return (\n \n
Current theme: {theme}
\n
setTheme(theme === 'light' ? 'dark' : 'light')}>\n Toggle Theme\n \n
\n );\n}\n\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"External state managers\"}),`\n`,(0,n.jsx)(e.p,{children:\"External state managers like Redux or MobX are designed for complex state management needs. They provide advanced features such as middleware, time-travel debugging, and the ability to manage state across a large application.\"}),`\n`,(0,n.jsx)(e.h4,{children:\"When to use external state managers\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:\"When the state management needs are complex and involve many interconnected pieces of state\"}),`\n`,(0,n.jsx)(e.li,{children:\"When you need advanced features like middleware, time-travel debugging, or dev tools\"}),`\n`,(0,n.jsx)(e.li,{children:\"When the state needs to be shared across a large application with many components\"}),`\n`]}),`\n`,(0,n.jsx)(e.h4,{children:\"Example with Redux\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-jsx\",children:`// actions.js\nexport const increment = () => ({ type: 'INCREMENT' });\n\n// reducer.js\nconst initialState = { count: 0 };\n\nfunction counterReducer(state = initialState, action) {\n switch (action.type) {\n case 'INCREMENT':\n return { ...state, count: state.count + 1 };\n default:\n return state;\n }\n}\n\nexport default counterReducer;\n\n// store.js\nimport { createStore } from 'redux';\nimport counterReducer from './reducer';\n\nconst store = createStore(counterReducer);\n\nexport default store;\n\n// Counter.js\nimport React from 'react';\nimport { useSelector, useDispatch } from 'react-redux';\nimport { increment } from './actions';\n\nfunction Counter() {\n const count = useSelector((state) => state.count);\n const dispatch = useDispatch();\n\n return (\n \n
Count: {count}
\n
dispatch(increment())}>Increment \n
\n );\n}\n\n// App.js\nimport React from 'react';\nimport { Provider } from 'react-redux';\nimport store from './store';\nimport Counter from './Counter';\n\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn/state-a-components-memory\",children:\"React documentation on state\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/learn/passing-data-deeply-with-context\",children:\"React documentation on context\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://redux.js.org/\",children:\"Redux documentation\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://mobx.js.org/README.html\",children:\"MobX documentation\"})}),`\n`]})]})}function R(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var y=R;return b(w);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-decide-between-using-react-state-context-and-external-state-managers/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/how-do-you-decide-between-using-react-state-context-and-external-state-managers/locales/zh-CN.json
index d7ec920dd..0398b2f99 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-decide-between-using-react-state-context-and-external-state-managers/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-decide-between-using-react-state-context-and-external-state-managers/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "您如何决定使用 React 状态、上下文和外部状态管理器?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/how-do-you-decide-between-using-react-state-context-and-external-state-managers/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var a=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var f=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),R=(t,n)=>{for(var r in n)o(t,r,{get:n[r],enumerable:!0})},h=(t,n,r,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of m(n))!x.call(t,c)&&c!==r&&o(t,c,{get:()=>n[c],enumerable:!(i=u(n,c))||i.enumerable});return t};var C=(t,n,r)=>(r=t!=null?a(p(t)):{},h(n||!t||!t.__esModule?o(r,\"default\",{value:t,enumerable:!0}):r,t)),j=t=>h(o({},\"__esModule\",{value:!0}),t);var d=f((M,l)=>{l.exports=_jsx_runtime});var b={};R(b,{default:()=>v,frontmatter:()=>g});var e=C(d()),g={title:\"\\u60A8\\u5982\\u4F55\\u51B3\\u5B9A\\u4F7F\\u7528 React \\u72B6\\u6001\\u3001\\u4E0A\\u4E0B\\u6587\\u548C\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\\uFF1F\"};function s(t){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",pre:\"pre\",code:\"code\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5728 React \\u72B6\\u6001\\u3001\\u4E0A\\u4E0B\\u6587\\u548C\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\\u4E4B\\u95F4\\u8FDB\\u884C\\u9009\\u62E9\\u53D6\\u51B3\\u4E8E\\u60A8\\u7684\\u5E94\\u7528\\u7A0B\\u5E8F\\u72B6\\u6001\\u7BA1\\u7406\\u9700\\u6C42\\u7684\\u590D\\u6742\\u6027\\u548C\\u8303\\u56F4\\u3002\\u5C06 React \\u72B6\\u6001\\u7528\\u4E8E\\u672C\\u5730\\u7EC4\\u4EF6\\u72B6\\u6001\\uFF0C\\u5C06 React \\u4E0A\\u4E0B\\u6587\\u7528\\u4E8E\\u9700\\u8981\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u5171\\u4EAB\\u7684\\u5168\\u5C40\\u72B6\\u6001\\uFF0C\\u5C06 Redux \\u6216 MobX \\u7B49\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\\u7528\\u4E8E\\u9700\\u8981\\u9AD8\\u7EA7\\u529F\\u80FD\\uFF08\\u5982\\u4E2D\\u95F4\\u4EF6\\u3001\\u65F6\\u95F4\\u65C5\\u884C\\u8C03\\u8BD5\\uFF09\\u6216\\u9700\\u8981\\u5728\\u5927\\u578B\\u5E94\\u7528\\u7A0B\\u5E8F\\u4E4B\\u95F4\\u5171\\u4EAB\\u72B6\\u6001\\u7684\\u590D\\u6742\\u72B6\\u6001\\u7BA1\\u7406\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u51B3\\u5B9A\\u4F7F\\u7528 React \\u72B6\\u6001\\u3001\\u4E0A\\u4E0B\\u6587\\u548C\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\"}),`\n`,(0,e.jsx)(n.h3,{children:\"React \\u72B6\\u6001\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u72B6\\u6001\\u6700\\u9002\\u5408\\u7528\\u4E8E\\u7BA1\\u7406\\u5355\\u4E2A\\u7EC4\\u4EF6\\u4E2D\\u7684\\u672C\\u5730\\u72B6\\u6001\\u3002\\u5B83\\u6613\\u4E8E\\u4F7F\\u7528\\uFF0C\\u5E76\\u63D0\\u4F9B\\u4E86\\u4E00\\u79CD\\u76F4\\u63A5\\u7684\\u65B9\\u5F0F\\u6765\\u5904\\u7406\\u4E0D\\u9700\\u8981\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u5171\\u4EAB\\u7684\\u72B6\\u6001\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F55\\u65F6\\u4F7F\\u7528 React \\u72B6\\u6001\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u72B6\\u6001\\u4EC5\\u4E0E\\u5355\\u4E2A\\u7EC4\\u4EF6\\u76F8\\u5173\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u72B6\\u6001\\u4E0D\\u9700\\u8981\\u88AB\\u5176\\u4ED6\\u7EC4\\u4EF6\\u8BBF\\u95EE\\u6216\\u4FEE\\u6539\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u60A8\\u5E0C\\u671B\\u4FDD\\u6301\\u7EC4\\u4EF6\\u81EA\\u5305\\u542B\\u4E14\\u6613\\u4E8E\\u7406\\u89E3\\u65F6\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React, { useState } from 'react';\n\nfunction Counter() {\n const [count, setCount] = useState(0);\n\n return (\n \n
Count: {count}
\n
setCount(count + 1)}>Increment \n
\n );\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"React \\u4E0A\\u4E0B\\u6587\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u4E0A\\u4E0B\\u6587\\u5BF9\\u4E8E\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u5171\\u4EAB\\u72B6\\u6001\\u975E\\u5E38\\u6709\\u7528\\uFF0C\\u800C\\u65E0\\u9700\\u901A\\u8FC7\\u7EC4\\u4EF6\\u6811\\u7684\\u6BCF\\u4E00\\u5C42\\u4F20\\u9012 props\\u3002\\u5B83\\u975E\\u5E38\\u9002\\u5408\\u9700\\u8981\\u88AB\\u8BB8\\u591A\\u7EC4\\u4EF6\\u8BBF\\u95EE\\u7684\\u5168\\u5C40\\u72B6\\u6001\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F55\\u65F6\\u4F7F\\u7528 React \\u4E0A\\u4E0B\\u6587\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u60A8\\u9700\\u8981\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u5171\\u4EAB\\u72B6\\u6001\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u60A8\\u60F3\\u907F\\u514D prop \\u94BB\\u53D6\\uFF08\\u901A\\u8FC7\\u591A\\u5C42\\u7EC4\\u4EF6\\u4F20\\u9012 props\\uFF09\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u72B6\\u6001\\u76F8\\u5BF9\\u7B80\\u5355\\u4E14\\u4E0D\\u9700\\u8981\\u9AD8\\u7EA7\\u72B6\\u6001\\u7BA1\\u7406\\u529F\\u80FD\\u65F6\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React, { createContext, useContext, useState } from 'react';\n\nconst ThemeContext = createContext();\n\nfunction ThemeProvider({ children }) {\n const [theme, setTheme] = useState('light');\n\n return (\n \n {children}\n \n );\n}\n\nfunction ThemedComponent() {\n const { theme, setTheme } = useContext(ThemeContext);\n\n return (\n \n
Current theme: {theme}
\n
setTheme(theme === 'light' ? 'dark' : 'light')}>\n \\u5207\\u6362\\u4E3B\\u9898\n \n
\n );\n}\n\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\"}),`\n`,(0,e.jsx)(n.p,{children:\"Redux \\u6216 MobX \\u7B49\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\\u4E13\\u4E3A\\u590D\\u6742\\u7684\\u72B6\\u6001\\u7BA1\\u7406\\u9700\\u6C42\\u800C\\u8BBE\\u8BA1\\u3002\\u5B83\\u4EEC\\u63D0\\u4F9B\\u9AD8\\u7EA7\\u529F\\u80FD\\uFF0C\\u4F8B\\u5982\\u4E2D\\u95F4\\u4EF6\\u3001\\u65F6\\u95F4\\u65C5\\u884C\\u8C03\\u8BD5\\u4EE5\\u53CA\\u5728\\u5927\\u578B\\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u7BA1\\u7406\\u72B6\\u6001\\u7684\\u80FD\\u529B\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F55\\u65F6\\u4F7F\\u7528\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u72B6\\u6001\\u7BA1\\u7406\\u9700\\u6C42\\u590D\\u6742\\u5E76\\u6D89\\u53CA\\u8BB8\\u591A\\u76F8\\u4E92\\u5173\\u8054\\u7684\\u72B6\\u6001\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u60A8\\u9700\\u8981\\u9AD8\\u7EA7\\u529F\\u80FD\\uFF08\\u5982\\u4E2D\\u95F4\\u4EF6\\u3001\\u65F6\\u95F4\\u65C5\\u884C\\u8C03\\u8BD5\\u6216\\u5F00\\u53D1\\u5DE5\\u5177\\uFF09\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u9700\\u8981\\u5728\\u5177\\u6709\\u8BB8\\u591A\\u7EC4\\u4EF6\\u7684\\u5927\\u578B\\u5E94\\u7528\\u7A0B\\u5E8F\\u4E4B\\u95F4\\u5171\\u4EAB\\u72B6\\u6001\\u65F6\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"Redux \\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`// actions.js\nexport const increment = () => ({ type: 'INCREMENT' });\n\n// reducer.js\nconst initialState = { count: 0 };\n\nfunction counterReducer(state = initialState, action) {\n switch (action.type) {\n case 'INCREMENT':\n return { ...state, count: state.count + 1 };\n default:\n return state;\n }\n}\n\nexport default counterReducer;\n\n// store.js\nimport { createStore } from 'redux';\nimport counterReducer from './reducer';\n\nconst store = createStore(counterReducer);\n\nexport default store;\n\n// Counter.js\nimport React from 'react';\nimport { useSelector, useDispatch } from 'react-redux';\nimport { increment } from './actions';\n\nfunction Counter() {\n const count = useSelector((state) => state.count);\n const dispatch = useDispatch();\n\n return (\n \n
Count: {count}
\n
dispatch(increment())}>Increment \n
\n );\n}\n\n// App.js\nimport React from 'react';\nimport { Provider } from 'react-redux';\nimport store from './store';\nimport Counter from './Counter';\n\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/state-and-lifecycle.html\",children:\"React \\u72B6\\u6001\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/context.html\",children:\"React \\u4E0A\\u4E0B\\u6587\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://redux.js.org/\",children:\"Redux \\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://mobx.js.org/README.html\",children:\"MobX \\u6587\\u6863\"})}),`\n`]})]})}function T(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(s,t)})):s(t)}var v=T;return j(b);})();\n;return Component;"
+ "solution": "var Component=(()=>{var s=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var f=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),R=(t,n)=>{for(var r in n)o(t,r,{get:n[r],enumerable:!0})},h=(t,n,r,i)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of m(n))!x.call(t,c)&&c!==r&&o(t,c,{get:()=>n[c],enumerable:!(i=u(n,c))||i.enumerable});return t};var C=(t,n,r)=>(r=t!=null?s(p(t)):{},h(n||!t||!t.__esModule?o(r,\"default\",{value:t,enumerable:!0}):r,t)),j=t=>h(o({},\"__esModule\",{value:!0}),t);var d=f((M,a)=>{a.exports=_jsx_runtime});var b={};R(b,{default:()=>T,frontmatter:()=>v});var e=C(d()),v={title:\"\\u60A8\\u5982\\u4F55\\u51B3\\u5B9A\\u4F7F\\u7528 React \\u72B6\\u6001\\u3001\\u4E0A\\u4E0B\\u6587\\u548C\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\\uFF1F\"};function l(t){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",pre:\"pre\",code:\"code\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u5728 React \\u72B6\\u6001\\u3001\\u4E0A\\u4E0B\\u6587\\u548C\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\\u4E4B\\u95F4\\u8FDB\\u884C\\u9009\\u62E9\\u53D6\\u51B3\\u4E8E\\u60A8\\u7684\\u5E94\\u7528\\u7A0B\\u5E8F\\u72B6\\u6001\\u7BA1\\u7406\\u9700\\u6C42\\u7684\\u590D\\u6742\\u6027\\u548C\\u8303\\u56F4\\u3002\\u5C06 React \\u72B6\\u6001\\u7528\\u4E8E\\u672C\\u5730\\u7EC4\\u4EF6\\u72B6\\u6001\\uFF0C\\u5C06 React \\u4E0A\\u4E0B\\u6587\\u7528\\u4E8E\\u9700\\u8981\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u5171\\u4EAB\\u7684\\u5168\\u5C40\\u72B6\\u6001\\uFF0C\\u5C06 Redux \\u6216 MobX \\u7B49\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\\u7528\\u4E8E\\u9700\\u8981\\u9AD8\\u7EA7\\u529F\\u80FD\\uFF08\\u5982\\u4E2D\\u95F4\\u4EF6\\u3001\\u65F6\\u95F4\\u65C5\\u884C\\u8C03\\u8BD5\\uFF09\\u6216\\u9700\\u8981\\u5728\\u5927\\u578B\\u5E94\\u7528\\u7A0B\\u5E8F\\u4E4B\\u95F4\\u5171\\u4EAB\\u72B6\\u6001\\u7684\\u590D\\u6742\\u72B6\\u6001\\u7BA1\\u7406\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u51B3\\u5B9A\\u4F7F\\u7528 React \\u72B6\\u6001\\u3001\\u4E0A\\u4E0B\\u6587\\u548C\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\"}),`\n`,(0,e.jsx)(n.h3,{children:\"React \\u72B6\\u6001\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u72B6\\u6001\\u6700\\u9002\\u5408\\u7528\\u4E8E\\u7BA1\\u7406\\u5355\\u4E2A\\u7EC4\\u4EF6\\u4E2D\\u7684\\u672C\\u5730\\u72B6\\u6001\\u3002\\u5B83\\u6613\\u4E8E\\u4F7F\\u7528\\uFF0C\\u5E76\\u63D0\\u4F9B\\u4E86\\u4E00\\u79CD\\u76F4\\u63A5\\u7684\\u65B9\\u5F0F\\u6765\\u5904\\u7406\\u4E0D\\u9700\\u8981\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u5171\\u4EAB\\u7684\\u72B6\\u6001\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F55\\u65F6\\u4F7F\\u7528 React \\u72B6\\u6001\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u72B6\\u6001\\u4EC5\\u4E0E\\u5355\\u4E2A\\u7EC4\\u4EF6\\u76F8\\u5173\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u72B6\\u6001\\u4E0D\\u9700\\u8981\\u88AB\\u5176\\u4ED6\\u7EC4\\u4EF6\\u8BBF\\u95EE\\u6216\\u4FEE\\u6539\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u60A8\\u5E0C\\u671B\\u4FDD\\u6301\\u7EC4\\u4EF6\\u81EA\\u5305\\u542B\\u4E14\\u6613\\u4E8E\\u7406\\u89E3\\u65F6\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React, { useState } from 'react';\n\nfunction Counter() {\n const [count, setCount] = useState(0);\n\n return (\n \n
Count: {count}
\n
setCount(count + 1)}>Increment \n
\n );\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"React \\u4E0A\\u4E0B\\u6587\"}),`\n`,(0,e.jsx)(n.p,{children:\"React \\u4E0A\\u4E0B\\u6587\\u5BF9\\u4E8E\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u5171\\u4EAB\\u72B6\\u6001\\u975E\\u5E38\\u6709\\u7528\\uFF0C\\u800C\\u65E0\\u9700\\u901A\\u8FC7\\u7EC4\\u4EF6\\u6811\\u7684\\u6BCF\\u4E00\\u5C42\\u4F20\\u9012 props\\u3002\\u5B83\\u975E\\u5E38\\u9002\\u5408\\u9700\\u8981\\u88AB\\u8BB8\\u591A\\u7EC4\\u4EF6\\u8BBF\\u95EE\\u7684\\u5168\\u5C40\\u72B6\\u6001\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F55\\u65F6\\u4F7F\\u7528 React \\u4E0A\\u4E0B\\u6587\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u60A8\\u9700\\u8981\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E4B\\u95F4\\u5171\\u4EAB\\u72B6\\u6001\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u60A8\\u60F3\\u907F\\u514D prop \\u94BB\\u53D6\\uFF08\\u901A\\u8FC7\\u591A\\u5C42\\u7EC4\\u4EF6\\u4F20\\u9012 props\\uFF09\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u72B6\\u6001\\u76F8\\u5BF9\\u7B80\\u5355\\u4E14\\u4E0D\\u9700\\u8981\\u9AD8\\u7EA7\\u72B6\\u6001\\u7BA1\\u7406\\u529F\\u80FD\\u65F6\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`import React, { createContext, useContext, useState } from 'react';\n\nconst ThemeContext = createContext();\n\nfunction ThemeProvider({ children }) {\n const [theme, setTheme] = useState('light');\n\n return (\n \n {children}\n \n );\n}\n\nfunction ThemedComponent() {\n const { theme, setTheme } = useContext(ThemeContext);\n\n return (\n \n
Current theme: {theme}
\n
setTheme(theme === 'light' ? 'dark' : 'light')}>\n \\u5207\\u6362\\u4E3B\\u9898\n \n
\n );\n}\n\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\"}),`\n`,(0,e.jsx)(n.p,{children:\"Redux \\u6216 MobX \\u7B49\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\\u4E13\\u4E3A\\u590D\\u6742\\u7684\\u72B6\\u6001\\u7BA1\\u7406\\u9700\\u6C42\\u800C\\u8BBE\\u8BA1\\u3002\\u5B83\\u4EEC\\u63D0\\u4F9B\\u9AD8\\u7EA7\\u529F\\u80FD\\uFF0C\\u4F8B\\u5982\\u4E2D\\u95F4\\u4EF6\\u3001\\u65F6\\u95F4\\u65C5\\u884C\\u8C03\\u8BD5\\u4EE5\\u53CA\\u5728\\u5927\\u578B\\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u7BA1\\u7406\\u72B6\\u6001\\u7684\\u80FD\\u529B\\u3002\"}),`\n`,(0,e.jsx)(n.h4,{children:\"\\u4F55\\u65F6\\u4F7F\\u7528\\u5916\\u90E8\\u72B6\\u6001\\u7BA1\\u7406\\u5668\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u72B6\\u6001\\u7BA1\\u7406\\u9700\\u6C42\\u590D\\u6742\\u5E76\\u6D89\\u53CA\\u8BB8\\u591A\\u76F8\\u4E92\\u5173\\u8054\\u7684\\u72B6\\u6001\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u60A8\\u9700\\u8981\\u9AD8\\u7EA7\\u529F\\u80FD\\uFF08\\u5982\\u4E2D\\u95F4\\u4EF6\\u3001\\u65F6\\u95F4\\u65C5\\u884C\\u8C03\\u8BD5\\u6216\\u5F00\\u53D1\\u5DE5\\u5177\\uFF09\\u65F6\"}),`\n`,(0,e.jsx)(n.li,{children:\"\\u5F53\\u9700\\u8981\\u5728\\u5177\\u6709\\u8BB8\\u591A\\u7EC4\\u4EF6\\u7684\\u5927\\u578B\\u5E94\\u7528\\u7A0B\\u5E8F\\u4E4B\\u95F4\\u5171\\u4EAB\\u72B6\\u6001\\u65F6\"}),`\n`]}),`\n`,(0,e.jsx)(n.h4,{children:\"Redux \\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-jsx\",children:`// actions.js\nexport const increment = () => ({ type: 'INCREMENT' });\n\n// reducer.js\nconst initialState = { count: 0 };\n\nfunction counterReducer(state = initialState, action) {\n switch (action.type) {\n case 'INCREMENT':\n return { ...state, count: state.count + 1 };\n default:\n return state;\n }\n}\n\nexport default counterReducer;\n\n// store.js\nimport { createStore } from 'redux';\nimport counterReducer from './reducer';\n\nconst store = createStore(counterReducer);\n\nexport default store;\n\n// Counter.js\nimport React from 'react';\nimport { useSelector, useDispatch } from 'react-redux';\nimport { increment } from './actions';\n\nfunction Counter() {\n const count = useSelector((state) => state.count);\n const dispatch = useDispatch();\n\n return (\n \n
Count: {count}
\n
dispatch(increment())}>Increment \n
\n );\n}\n\n// App.js\nimport React from 'react';\nimport { Provider } from 'react-redux';\nimport store from './store';\nimport Counter from './Counter';\n\nfunction App() {\n return (\n \n \n \n );\n}\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/learn/state-a-components-memory\",children:\"React \\u72B6\\u6001\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/learn/passing-data-deeply-with-context\",children:\"React \\u4E0A\\u4E0B\\u6587\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://redux.js.org/\",children:\"Redux \\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://mobx.js.org/README.html\",children:\"MobX \\u6587\\u6863\"})}),`\n`]})]})}function g(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(l,t)})):l(t)}var T=g;return j(b);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-handle-asynchronous-data-loading-in-react-applications/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-do-you-handle-asynchronous-data-loading-in-react-applications/locales/en-US.json
index f96f0e71c..3b73fdde3 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-handle-asynchronous-data-loading-in-react-applications/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-handle-asynchronous-data-loading-in-react-applications/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How do you handle asynchronous data loading in React applications?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/how-do-you-handle-asynchronous-data-loading-in-react-applications/en-US.mdx"
},
- "solution": "var Component=(()=>{var l=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),y=(t,e)=>{for(var a in e)o(t,a,{get:e[a],enumerable:!0})},s=(t,e,a,c)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of f(e))!g.call(t,r)&&r!==a&&o(t,r,{get:()=>e[r],enumerable:!(c=u(e,r))||c.enumerable});return t};var v=(t,e,a)=>(a=t!=null?l(p(t)):{},s(e||!t||!t.__esModule?o(a,\"default\",{value:t,enumerable:!0}):a,t)),D=t=>s(o({},\"__esModule\",{value:!0}),t);var d=m((F,i)=>{i.exports=_jsx_runtime});var S={};y(S,{default:()=>w,frontmatter:()=>E});var n=v(d()),E={title:\"How do you handle asynchronous data loading in React applications?\"};function h(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",ul:\"ul\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In React applications, asynchronous data loading is typically handled using \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" and \",(0,n.jsx)(e.code,{children:\"useState\"}),\" hooks. You initiate the data fetch inside \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" and update the state with the fetched data. This ensures that the component re-renders with the new data. Here's a simple example:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import React, { useState, useEffect } from 'react';\n\nfunction DataFetchingComponent() {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n async function fetchData() {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n setLoading(false);\n }\n\n fetchData();\n }, []);\n\n if (loading) {\n return Loading...
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Handling asynchronous data loading in React applications\"}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" and \",(0,n.jsx)(e.code,{children:\"useState\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"The most common way to handle asynchronous data loading in React is by using the \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" and \",(0,n.jsx)(e.code,{children:\"useState\"}),\" hooks. \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" allows you to perform side effects, such as data fetching, and \",(0,n.jsx)(e.code,{children:\"useState\"}),\" helps manage the component's state.\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Initialize state\"}),\": Use \",(0,n.jsx)(e.code,{children:\"useState\"}),\" to create state variables for storing the fetched data and loading status.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Fetch data\"}),\": Use \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" to perform the data fetching when the component mounts.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Update state\"}),\": Once the data is fetched, update the state to trigger a re-render.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"Here's a detailed example:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import React, { useState, useEffect } from 'react';\n\nfunction DataFetchingComponent() {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n } catch (error) {\n console.error('Error fetching data:', error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n }, []);\n\n if (loading) {\n return Loading...
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Handling errors\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"It's important to handle errors that may occur during data fetching. You can use a \",(0,n.jsx)(e.code,{children:\"try-catch\"}),\" block within the \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" to catch and handle errors.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n } catch (error) {\n console.error('Error fetching data:', error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n}, []);\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Using custom hooks\"}),`\n`,(0,n.jsx)(e.p,{children:\"For better code reusability, you can create custom hooks to handle data fetching. This allows you to encapsulate the data fetching logic and reuse it across multiple components.\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import { useState, useEffect } from 'react';\n\nfunction useFetch(url) {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch(url);\n const result = await response.json();\n setData(result);\n } catch (error) {\n setError(error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n }, [url]);\n\n return { data, loading, error };\n}\n\nexport default useFetch;\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"You can then use this custom hook in your components:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import React from 'react';\nimport useFetch from './useFetch';\n\nfunction DataFetchingComponent() {\n const { data, loading, error } = useFetch('https://api.example.com/data');\n\n if (loading) {\n return Loading...
;\n }\n\n if (error) {\n return Error: {error.message}
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/hooks-intro.html\",children:\"React documentation on hooks\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://reactjs.org/docs/hooks-effect.html\",children:\"Using the Effect Hook\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\",children:\"Fetch API\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://javascript.info/async-await#error-handling\",children:\"Handling errors in async functions\"})}),`\n`]})]})}function j(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(h,t)})):h(t)}var w=j;return D(S);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),y=(t,e)=>{for(var a in e)c(t,a,{get:e[a],enumerable:!0})},s=(t,e,a,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let r of f(e))!g.call(t,r)&&r!==a&&c(t,r,{get:()=>e[r],enumerable:!(o=u(e,r))||o.enumerable});return t};var v=(t,e,a)=>(a=t!=null?h(p(t)):{},s(e||!t||!t.__esModule?c(a,\"default\",{value:t,enumerable:!0}):a,t)),D=t=>s(c({},\"__esModule\",{value:!0}),t);var d=m((F,i)=>{i.exports=_jsx_runtime});var j={};y(j,{default:()=>S,frontmatter:()=>E});var n=v(d()),E={title:\"How do you handle asynchronous data loading in React applications?\"};function l(t){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",ul:\"ul\",a:\"a\"},t.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"In React applications, asynchronous data loading is typically handled using \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" and \",(0,n.jsx)(e.code,{children:\"useState\"}),\" hooks. You initiate the data fetch inside \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" and update the state with the fetched data. This ensures that the component re-renders with the new data. Here's a simple example:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import React, { useState, useEffect } from 'react';\n\nfunction DataFetchingComponent() {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n async function fetchData() {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n setLoading(false);\n }\n\n fetchData();\n }, []);\n\n if (loading) {\n return Loading...
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"Handling asynchronous data loading in React applications\"}),`\n`,(0,n.jsxs)(e.h3,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" and \",(0,n.jsx)(e.code,{children:\"useState\"})]}),`\n`,(0,n.jsxs)(e.p,{children:[\"The most common way to handle asynchronous data loading in React is by using the \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" and \",(0,n.jsx)(e.code,{children:\"useState\"}),\" hooks. \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" allows you to perform side effects, such as data fetching, and \",(0,n.jsx)(e.code,{children:\"useState\"}),\" helps manage the component's state.\"]}),`\n`,(0,n.jsxs)(e.ol,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Initialize state\"}),\": Use \",(0,n.jsx)(e.code,{children:\"useState\"}),\" to create state variables for storing the fetched data and loading status.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Fetch data\"}),\": Use \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" to perform the data fetching when the component mounts.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.strong,{children:\"Update state\"}),\": Once the data is fetched, update the state to trigger a re-render.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"Here's a detailed example:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import React, { useState, useEffect } from 'react';\n\nfunction DataFetchingComponent() {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n } catch (error) {\n console.error('Error fetching data:', error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n }, []);\n\n if (loading) {\n return Loading...
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Handling errors\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"It's important to handle errors that may occur during data fetching. You can use a \",(0,n.jsx)(e.code,{children:\"try-catch\"}),\" block within the \",(0,n.jsx)(e.code,{children:\"useEffect\"}),\" to catch and handle errors.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n } catch (error) {\n console.error('Error fetching data:', error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n}, []);\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Using custom hooks\"}),`\n`,(0,n.jsx)(e.p,{children:\"For better code reusability, you can create custom hooks to handle data fetching. This allows you to encapsulate the data fetching logic and reuse it across multiple components.\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import { useState, useEffect } from 'react';\n\nfunction useFetch(url) {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch(url);\n const result = await response.json();\n setData(result);\n } catch (error) {\n setError(error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n }, [url]);\n\n return { data, loading, error };\n}\n\nexport default useFetch;\n`})}),`\n`,(0,n.jsx)(e.p,{children:\"You can then use this custom hook in your components:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-javascript\",children:`import React from 'react';\nimport useFetch from './useFetch';\n\nfunction DataFetchingComponent() {\n const { data, loading, error } = useFetch('https://api.example.com/data');\n\n if (loading) {\n return Loading...
;\n }\n\n if (error) {\n return Error: {error.message}
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/reference/react/hooks\",children:\"React documentation on hooks\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://react.dev/reference/react/useEffect\",children:\"React useEffect Hook\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\",children:\"Fetch API\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://javascript.info/async-await#error-handling\",children:\"Handling errors in async functions\"})}),`\n`]})]})}function w(t={}){let{wrapper:e}=t.components||{};return e?(0,n.jsx)(e,Object.assign({},t,{children:(0,n.jsx)(l,t)})):l(t)}var S=w;return D(j);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-handle-asynchronous-data-loading-in-react-applications/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/how-do-you-handle-asynchronous-data-loading-in-react-applications/locales/zh-CN.json
index 9c0e8d259..18363d524 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-handle-asynchronous-data-loading-in-react-applications/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-handle-asynchronous-data-loading-in-react-applications/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "如何在 React 应用程序中处理异步数据加载?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/how-do-you-handle-asynchronous-data-loading-in-react-applications/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var c=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),v=(t,n)=>{for(var r in n)c(t,r,{get:n[r],enumerable:!0})},o=(t,n,r,s)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let a of u(n))!g.call(t,a)&&a!==r&&c(t,a,{get:()=>n[a],enumerable:!(s=f(n,a))||s.enumerable});return t};var D=(t,n,r)=>(r=t!=null?h(p(t)):{},o(n||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),E=t=>o(c({},\"__esModule\",{value:!0}),t);var l=m((L,i)=>{i.exports=_jsx_runtime});var x={};v(x,{default:()=>y,frontmatter:()=>j});var e=D(l()),j={title:\"\\u5982\\u4F55\\u5728 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u5904\\u7406\\u5F02\\u6B65\\u6570\\u636E\\u52A0\\u8F7D\\uFF1F\"};function d(t){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",ul:\"ul\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\uFF0C\\u5F02\\u6B65\\u6570\\u636E\\u52A0\\u8F7D\\u901A\\u5E38\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"useState\"}),\" \\u94A9\\u5B50\\u6765\\u5904\\u7406\\u3002\\u60A8\\u5728 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u5185\\u90E8\\u542F\\u52A8\\u6570\\u636E\\u83B7\\u53D6\\uFF0C\\u5E76\\u4F7F\\u7528\\u83B7\\u53D6\\u7684\\u6570\\u636E\\u66F4\\u65B0\\u72B6\\u6001\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u7EC4\\u4EF6\\u4F7F\\u7528\\u65B0\\u6570\\u636E\\u91CD\\u65B0\\u6E32\\u67D3\\u3002\\u8FD9\\u662F\\u4E00\\u4E2A\\u7B80\\u5355\\u7684\\u4F8B\\u5B50\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import React, { useState, useEffect } from 'react';\n\nfunction DataFetchingComponent() {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n async function fetchData() {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n setLoading(false);\n }\n\n fetchData();\n }, []);\n\n if (loading) {\n return Loading...
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5728 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u5904\\u7406\\u5F02\\u6B65\\u6570\\u636E\\u52A0\\u8F7D\"}),`\n`,(0,e.jsxs)(n.h3,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"useState\"})]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5904\\u7406 React \\u4E2D\\u5F02\\u6B65\\u6570\\u636E\\u52A0\\u8F7D\\u6700\\u5E38\\u89C1\\u7684\\u65B9\\u6CD5\\u662F\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"useState\"}),\" \\u94A9\\u5B50\\u3002\",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u5141\\u8BB8\\u60A8\\u6267\\u884C\\u526F\\u4F5C\\u7528\\uFF0C\\u4F8B\\u5982\\u6570\\u636E\\u83B7\\u53D6\\uFF0C\\u800C \",(0,e.jsx)(n.code,{children:\"useState\"}),\" \\u6709\\u52A9\\u4E8E\\u7BA1\\u7406\\u7EC4\\u4EF6\\u7684\\u72B6\\u6001\\u3002\"]}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u521D\\u59CB\\u5316\\u72B6\\u6001\"}),\"\\uFF1A\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useState\"}),\" \\u521B\\u5EFA\\u72B6\\u6001\\u53D8\\u91CF\\u6765\\u5B58\\u50A8\\u83B7\\u53D6\\u7684\\u6570\\u636E\\u548C\\u52A0\\u8F7D\\u72B6\\u6001\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u83B7\\u53D6\\u6570\\u636E\"}),\"\\uFF1A\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u5728\\u7EC4\\u4EF6\\u6302\\u8F7D\\u65F6\\u6267\\u884C\\u6570\\u636E\\u83B7\\u53D6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u66F4\\u65B0\\u72B6\\u6001\"}),\"\\uFF1A\\u83B7\\u53D6\\u6570\\u636E\\u540E\\uFF0C\\u66F4\\u65B0\\u72B6\\u6001\\u4EE5\\u89E6\\u53D1\\u91CD\\u65B0\\u6E32\\u67D3\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u662F\\u4E00\\u4E2A\\u8BE6\\u7EC6\\u7684\\u4F8B\\u5B50\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import React, { useState, useEffect } from 'react';\n\nfunction DataFetchingComponent() {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n } catch (error) {\n console.error('Error fetching data:', error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n }, []);\n\n if (loading) {\n return Loading...
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5904\\u7406\\u9519\\u8BEF\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5904\\u7406\\u6570\\u636E\\u83B7\\u53D6\\u671F\\u95F4\\u53EF\\u80FD\\u53D1\\u751F\\u7684\\u9519\\u8BEF\\u975E\\u5E38\\u91CD\\u8981\\u3002\\u60A8\\u53EF\\u4EE5\\u5728 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u4E2D\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"try-catch\"}),\" \\u5757\\u6765\\u6355\\u83B7\\u548C\\u5904\\u7406\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n } catch (error) {\n console.error('Error fetching data:', error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n}, []);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4F7F\\u7528\\u81EA\\u5B9A\\u4E49\\u94A9\\u5B50\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4E3A\\u4E86\\u66F4\\u597D\\u5730\\u91CD\\u7528\\u4EE3\\u7801\\uFF0C\\u60A8\\u53EF\\u4EE5\\u521B\\u5EFA\\u81EA\\u5B9A\\u4E49\\u94A9\\u5B50\\u6765\\u5904\\u7406\\u6570\\u636E\\u83B7\\u53D6\\u3002\\u8FD9\\u5141\\u8BB8\\u60A8\\u5C01\\u88C5\\u6570\\u636E\\u83B7\\u53D6\\u903B\\u8F91\\u5E76\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E2D\\u91CD\\u7528\\u5B83\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import { useState, useEffect } from 'react';\n\nfunction useFetch(url) {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch(url);\n const result = await response.json();\n setData(result);\n } catch (error) {\n setError(error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n }, [url]);\n\n return { data, loading, error };\n}\n\nexport default useFetch;\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7136\\u540E\\uFF0C\\u60A8\\u53EF\\u4EE5\\u5728\\u7EC4\\u4EF6\\u4E2D\\u4F7F\\u7528\\u6B64\\u81EA\\u5B9A\\u4E49\\u94A9\\u5B50\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import React from 'react';\nimport useFetch from './useFetch';\n\nfunction DataFetchingComponent() {\n const { data, loading, error } = useFetch('https://api.example.com/data');\n\n if (loading) {\n return Loading...
;\n }\n\n if (error) {\n return Error: {error.message}
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/hooks-intro.html\",children:\"React \\u94A9\\u5B50\\u6587\\u6863\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/hooks-effect.html\",children:\"\\u4F7F\\u7528 Effect \\u94A9\\u5B50\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\",children:\"Fetch API\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/async-await#error-handling\",children:\"\\u5904\\u7406\\u5F02\\u6B65\\u51FD\\u6570\\u4E2D\\u7684\\u9519\\u8BEF\"})}),`\n`]})]})}function S(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(d,t)})):d(t)}var y=S;return E(x);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var c=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var m=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),v=(t,n)=>{for(var r in n)c(t,r,{get:n[r],enumerable:!0})},o=(t,n,r,s)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let a of f(n))!g.call(t,a)&&a!==r&&c(t,a,{get:()=>n[a],enumerable:!(s=u(n,a))||s.enumerable});return t};var D=(t,n,r)=>(r=t!=null?h(p(t)):{},o(n||!t||!t.__esModule?c(r,\"default\",{value:t,enumerable:!0}):r,t)),E=t=>o(c({},\"__esModule\",{value:!0}),t);var d=m((L,i)=>{i.exports=_jsx_runtime});var x={};v(x,{default:()=>y,frontmatter:()=>S});var e=D(d()),S={title:\"\\u5982\\u4F55\\u5728 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u5904\\u7406\\u5F02\\u6B65\\u6570\\u636E\\u52A0\\u8F7D\\uFF1F\"};function l(t){let n=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",ol:\"ol\",li:\"li\",strong:\"strong\",ul:\"ul\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5728 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\uFF0C\\u5F02\\u6B65\\u6570\\u636E\\u52A0\\u8F7D\\u901A\\u5E38\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"useState\"}),\" \\u94A9\\u5B50\\u6765\\u5904\\u7406\\u3002\\u60A8\\u5728 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u5185\\u90E8\\u542F\\u52A8\\u6570\\u636E\\u83B7\\u53D6\\uFF0C\\u5E76\\u4F7F\\u7528\\u83B7\\u53D6\\u7684\\u6570\\u636E\\u66F4\\u65B0\\u72B6\\u6001\\u3002\\u8FD9\\u786E\\u4FDD\\u4E86\\u7EC4\\u4EF6\\u4F7F\\u7528\\u65B0\\u6570\\u636E\\u91CD\\u65B0\\u6E32\\u67D3\\u3002\\u8FD9\\u662F\\u4E00\\u4E2A\\u7B80\\u5355\\u7684\\u4F8B\\u5B50\\uFF1A\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import React, { useState, useEffect } from 'react';\n\nfunction DataFetchingComponent() {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n async function fetchData() {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n setLoading(false);\n }\n\n fetchData();\n }, []);\n\n if (loading) {\n return Loading...
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5728 React \\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u5904\\u7406\\u5F02\\u6B65\\u6570\\u636E\\u52A0\\u8F7D\"}),`\n`,(0,e.jsxs)(n.h3,{children:[\"\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"useState\"})]}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5904\\u7406 React \\u4E2D\\u5F02\\u6B65\\u6570\\u636E\\u52A0\\u8F7D\\u6700\\u5E38\\u89C1\\u7684\\u65B9\\u6CD5\\u662F\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u548C \",(0,e.jsx)(n.code,{children:\"useState\"}),\" \\u94A9\\u5B50\\u3002\",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u5141\\u8BB8\\u60A8\\u6267\\u884C\\u526F\\u4F5C\\u7528\\uFF0C\\u4F8B\\u5982\\u6570\\u636E\\u83B7\\u53D6\\uFF0C\\u800C \",(0,e.jsx)(n.code,{children:\"useState\"}),\" \\u6709\\u52A9\\u4E8E\\u7BA1\\u7406\\u7EC4\\u4EF6\\u7684\\u72B6\\u6001\\u3002\"]}),`\n`,(0,e.jsxs)(n.ol,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u521D\\u59CB\\u5316\\u72B6\\u6001\"}),\"\\uFF1A\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useState\"}),\" \\u521B\\u5EFA\\u72B6\\u6001\\u53D8\\u91CF\\u6765\\u5B58\\u50A8\\u83B7\\u53D6\\u7684\\u6570\\u636E\\u548C\\u52A0\\u8F7D\\u72B6\\u6001\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u83B7\\u53D6\\u6570\\u636E\"}),\"\\uFF1A\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u5728\\u7EC4\\u4EF6\\u6302\\u8F7D\\u65F6\\u6267\\u884C\\u6570\\u636E\\u83B7\\u53D6\\u3002\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u66F4\\u65B0\\u72B6\\u6001\"}),\"\\uFF1A\\u83B7\\u53D6\\u6570\\u636E\\u540E\\uFF0C\\u66F4\\u65B0\\u72B6\\u6001\\u4EE5\\u89E6\\u53D1\\u91CD\\u65B0\\u6E32\\u67D3\\u3002\"]}),`\n`]}),`\n`,(0,e.jsx)(n.p,{children:\"\\u8FD9\\u662F\\u4E00\\u4E2A\\u8BE6\\u7EC6\\u7684\\u4F8B\\u5B50\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import React, { useState, useEffect } from 'react';\n\nfunction DataFetchingComponent() {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n } catch (error) {\n console.error('Error fetching data:', error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n }, []);\n\n if (loading) {\n return Loading...
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5904\\u7406\\u9519\\u8BEF\"}),`\n`,(0,e.jsxs)(n.p,{children:[\"\\u5904\\u7406\\u6570\\u636E\\u83B7\\u53D6\\u671F\\u95F4\\u53EF\\u80FD\\u53D1\\u751F\\u7684\\u9519\\u8BEF\\u975E\\u5E38\\u91CD\\u8981\\u3002\\u60A8\\u53EF\\u4EE5\\u5728 \",(0,e.jsx)(n.code,{children:\"useEffect\"}),\" \\u4E2D\\u4F7F\\u7528 \",(0,e.jsx)(n.code,{children:\"try-catch\"}),\" \\u5757\\u6765\\u6355\\u83B7\\u548C\\u5904\\u7406\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch('https://api.example.com/data');\n const result = await response.json();\n setData(result);\n } catch (error) {\n console.error('Error fetching data:', error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n}, []);\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u4F7F\\u7528\\u81EA\\u5B9A\\u4E49\\u94A9\\u5B50\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u4E3A\\u4E86\\u66F4\\u597D\\u5730\\u91CD\\u7528\\u4EE3\\u7801\\uFF0C\\u60A8\\u53EF\\u4EE5\\u521B\\u5EFA\\u81EA\\u5B9A\\u4E49\\u94A9\\u5B50\\u6765\\u5904\\u7406\\u6570\\u636E\\u83B7\\u53D6\\u3002\\u8FD9\\u5141\\u8BB8\\u60A8\\u5C01\\u88C5\\u6570\\u636E\\u83B7\\u53D6\\u903B\\u8F91\\u5E76\\u5728\\u591A\\u4E2A\\u7EC4\\u4EF6\\u4E2D\\u91CD\\u7528\\u5B83\\u3002\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import { useState, useEffect } from 'react';\n\nfunction useFetch(url) {\n const [data, setData] = useState(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState(null);\n\n useEffect(() => {\n async function fetchData() {\n try {\n const response = await fetch(url);\n const result = await response.json();\n setData(result);\n } catch (error) {\n setError(error);\n } finally {\n setLoading(false);\n }\n }\n\n fetchData();\n }, [url]);\n\n return { data, loading, error };\n}\n\nexport default useFetch;\n`})}),`\n`,(0,e.jsx)(n.p,{children:\"\\u7136\\u540E\\uFF0C\\u60A8\\u53EF\\u4EE5\\u5728\\u7EC4\\u4EF6\\u4E2D\\u4F7F\\u7528\\u6B64\\u81EA\\u5B9A\\u4E49\\u94A9\\u5B50\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{className:\"language-javascript\",children:`import React from 'react';\nimport useFetch from './useFetch';\n\nfunction DataFetchingComponent() {\n const { data, loading, error } = useFetch('https://api.example.com/data');\n\n if (loading) {\n return Loading...
;\n }\n\n if (error) {\n return Error: {error.message}
;\n }\n\n return {JSON.stringify(data)}
;\n}\n`})}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/reference/react/hooks\",children:\"React documentation on hooks\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://react.dev/reference/react/useEffect\",children:\"React useEffect Hook\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\",children:\"Fetch API\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://javascript.info/async-await#error-handling\",children:\"Handling errors in async functions\"})}),`\n`]})]})}function j(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(l,t)})):l(t)}var y=j;return E(x);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-handle-errors-in-asynchronous-operations/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-do-you-handle-errors-in-asynchronous-operations/locales/en-US.json
index 9f6c44368..14d350c66 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-handle-errors-in-asynchronous-operations/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-handle-errors-in-asynchronous-operations/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How do you handle errors in asynchronous operations?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-do-you-handle-errors-in-asynchronous-operations/en-US.mdx"
},
- "solution": "var Component=(()=>{var d=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var y=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),f=(r,e)=>{for(var a in e)c(r,a,{get:e[a],enumerable:!0})},s=(r,e,a,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let o of u(e))!m.call(r,o)&&o!==a&&c(r,o,{get:()=>e[o],enumerable:!(t=p(e,o))||t.enumerable});return r};var w=(r,e,a)=>(a=r!=null?d(g(r)):{},s(e||!r||!r.__esModule?c(a,\"default\",{value:r,enumerable:!0}):a,r)),j=r=>s(c({},\"__esModule\",{value:!0}),r);var h=y((P,i)=>{i.exports=_jsx_runtime});var b={};f(b,{default:()=>D,frontmatter:()=>v});var n=w(h()),v={title:\"How do you handle errors in asynchronous operations?\"};function l(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"To handle errors in asynchronous operations, you can use \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" blocks with \",(0,n.jsx)(e.code,{children:\"async/await\"}),\" syntax or \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" method with Promises. For example, with \",(0,n.jsx)(e.code,{children:\"async/await\"}),\", you can wrap your code in a \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" block to catch any errors:\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nfetchData(); // Error fetching data: ....\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"With Promises, you can use the \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" method:\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data') // Invalid URl\n .then((response) => response.json())\n .then((data) => console.log(data))\n .catch((error) => console.error('Error fetching data:', error));\n`})}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsxs)(e.h2,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" with \",(0,n.jsx)(e.code,{children:\"async/await\"})]}),`\n`,(0,n.jsx)(e.h3,{children:\"Basic usage\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"When using \",(0,n.jsx)(e.code,{children:\"async/await\"}),\", you can handle errors by wrapping your asynchronous code in a \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" block. This allows you to catch any errors that occur during the execution of the \",(0,n.jsx)(e.code,{children:\"await\"}),\" statement.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nfetchData(); // Error fetching data: ....\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Nested asynchronous operations\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"If you have multiple asynchronous operations, you can nest \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" blocks to handle errors at different levels.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nasync function processData() {\n try {\n await fetchData();\n // Additional processing\n console.log(arr); // Trying to reference an undefined variable will throw an error\n } catch (error) {\n console.error('Error processing data:', error);\n }\n}\n\nprocessData();\n`})}),`\n`,(0,n.jsxs)(e.h2,{children:[\"Using \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" with Promises\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Basic usage\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"When working with Promises, you can handle errors using the \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" method. This method is called if the Promise is rejected.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data')\n .then((response) => response.json())\n .then((data) => console.log(data))\n .catch((error) => console.error('Error fetching data:', error));\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Chaining multiple Promises\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"If you have multiple Promises chained together, you can use a single \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" at the end to handle any errors that occur in any of the Promises.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data')\n .then((response) => response.json())\n .then((data) => {\n // Process data\n return processData(data);\n })\n .then((result) => {\n // Further processing\n console.log(result);\n })\n .catch((error) => console.error('Error in the chain:', error));\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await\",children:\"MDN Web Docs: async/await\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises\",children:\"MDN Web Docs: Promises\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://javascript.info/promise-error-handling\",children:\"JavaScript.info: Error handling with promises\"})}),`\n`]})]})}function x(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(l,r)})):l(r)}var D=x;return j(b);})();\n;return Component;"
+ "solution": "var Component=(()=>{var d=Object.create;var c=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var y=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),f=(r,e)=>{for(var o in e)c(r,o,{get:e[o],enumerable:!0})},s=(r,e,o,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of u(e))!g.call(r,a)&&a!==o&&c(r,a,{get:()=>e[a],enumerable:!(t=p(e,a))||t.enumerable});return r};var w=(r,e,o)=>(o=r!=null?d(m(r)):{},s(e||!r||!r.__esModule?c(o,\"default\",{value:r,enumerable:!0}):o,r)),j=r=>s(c({},\"__esModule\",{value:!0}),r);var h=y((P,i)=>{i.exports=_jsx_runtime});var U={};f(U,{default:()=>E,frontmatter:()=>v});var n=w(h()),v={title:\"How do you handle errors in asynchronous operations?\"};function l(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"To handle errors in asynchronous operations, you can use \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" blocks with \",(0,n.jsx)(e.code,{children:\"async/await\"}),\" syntax or \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" method with Promises. For example, with \",(0,n.jsx)(e.code,{children:\"async/await\"}),\", you can wrap your code in a \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" block to catch any errors:\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nfetchData(); // Error fetching data: ....\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"With Promises, you can use the \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" method:\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data') // Invalid URl\n .then((response) => response.json())\n .then((data) => console.log(data))\n .catch((error) => console.error('Error fetching data:', error));\n`})}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsxs)(e.h2,{children:[\"Using \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" with \",(0,n.jsx)(e.code,{children:\"async/await\"})]}),`\n`,(0,n.jsx)(e.h3,{children:\"Basic usage\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"When using \",(0,n.jsx)(e.code,{children:\"async/await\"}),\", you can handle errors by wrapping your asynchronous code in a \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" block. This allows you to catch any errors that occur during the execution of the \",(0,n.jsx)(e.code,{children:\"await\"}),\" statement.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nfetchData(); // Error fetching data: ....\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Nested asynchronous operations\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"If you have multiple asynchronous operations, you can nest \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" blocks to handle errors at different levels.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchUser() {\n // Simulate a successful async operation\n return { id: 1, name: 'Alice' };\n}\n\nasync function fetchUserPosts() {\n // Simulate a failed async operation\n throw new Error('Failed to fetch posts');\n}\n\nasync function loadUserData() {\n try {\n const user = await fetchUser();\n console.log('User:', user);\n\n try {\n const posts = await fetchUserPosts();\n console.log('Posts:', posts);\n } catch (postsError) {\n console.error('Error fetching posts:', postsError.message);\n }\n } catch (userError) {\n console.error('Error fetching user:', userError.message);\n }\n}\n\nloadUserData();\n`})}),`\n`,(0,n.jsxs)(e.h2,{children:[\"Using \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" with Promises\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"Basic usage\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"When working with Promises, you can handle errors using the \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" method. This method is called if the Promise is rejected.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data')\n .then((response) => response.json())\n .then((data) => console.log(data))\n .catch((error) => console.error('Error fetching data:', error));\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Chaining multiple Promises\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"If you have multiple Promises chained together, you can use a single \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" at the end to handle any errors that occur in any of the Promises.\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data')\n .then((response) => response.json())\n .then((data) => {\n // Process data\n return processData(data);\n })\n .then((result) => {\n // Further processing\n console.log(result);\n })\n .catch((error) => console.error('Error in the chain:', error));\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"Further reading\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await\",children:\"MDN Web Docs: async/await\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises\",children:\"MDN Web Docs: Promises\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://javascript.info/promise-error-handling\",children:\"JavaScript.info: Error handling with promises\"})}),`\n`]})]})}function x(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(l,r)})):l(r)}var E=x;return j(U);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-handle-errors-in-asynchronous-operations/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/how-do-you-handle-errors-in-asynchronous-operations/locales/zh-CN.json
index 3bb3ec58a..a82412431 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-handle-errors-in-asynchronous-operations/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-handle-errors-in-asynchronous-operations/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "如何处理异步操作中的错误?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-do-you-handle-errors-in-asynchronous-operations/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var d=Object.create;var t=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var g=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var u=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),y=(r,e)=>{for(var a in e)t(r,a,{get:e[a],enumerable:!0})},s=(r,e,a,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let c of m(e))!f.call(r,c)&&c!==a&&t(r,c,{get:()=>e[c],enumerable:!(o=p(e,c))||o.enumerable});return r};var j=(r,e,a)=>(a=r!=null?d(g(r)):{},s(e||!r||!r.__esModule?t(a,\"default\",{value:r,enumerable:!0}):a,r)),w=r=>s(t({},\"__esModule\",{value:!0}),r);var h=u((_,i)=>{i.exports=_jsx_runtime});var E={};y(E,{default:()=>x,frontmatter:()=>v});var n=j(h()),v={title:\"\\u5982\\u4F55\\u5904\\u7406\\u5F02\\u6B65\\u64CD\\u4F5C\\u4E2D\\u7684\\u9519\\u8BEF\\uFF1F\"};function l(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8981\\u5904\\u7406\\u5F02\\u6B65\\u64CD\\u4F5C\\u4E2D\\u7684\\u9519\\u8BEF\\uFF0C\\u53EF\\u4EE5\\u4F7F\\u7528\\u5E26\\u6709 \",(0,n.jsx)(e.code,{children:\"async/await\"}),\" \\u8BED\\u6CD5\\u7684 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u5757\\u6216\\u5E26\\u6709 Promises \\u7684 \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u65B9\\u6CD5\\u3002\\u4F8B\\u5982\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"async/await\"}),\"\\uFF0C\\u60A8\\u53EF\\u4EE5\\u5C06\\u4EE3\\u7801\\u5305\\u88C5\\u5728 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u5757\\u4E2D\\u4EE5\\u6355\\u83B7\\u4EFB\\u4F55\\u9519\\u8BEF\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nfetchData(); // Error fetching data: ....\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 Promises\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u65B9\\u6CD5\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data') // Invalid URl\n .then((response) => response.json())\n .then((data) => console.log(data))\n .catch((error) => console.error('Error fetching data:', error));\n`})}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsxs)(e.h2,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"async/await\"})]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u57FA\\u672C\\u7528\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"async/await\"}),\" \\u65F6\\uFF0C\\u60A8\\u53EF\\u4EE5\\u901A\\u8FC7\\u5C06\\u5F02\\u6B65\\u4EE3\\u7801\\u5305\\u88C5\\u5728 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u5757\\u4E2D\\u6765\\u5904\\u7406\\u9519\\u8BEF\\u3002\\u8FD9\\u5141\\u8BB8\\u60A8\\u6355\\u83B7\\u5728\\u6267\\u884C \",(0,n.jsx)(e.code,{children:\"await\"}),\" \\u8BED\\u53E5\\u671F\\u95F4\\u53D1\\u751F\\u7684\\u4EFB\\u4F55\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nfetchData(); // Error fetching data: ....\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5D4C\\u5957\\u5F02\\u6B65\\u64CD\\u4F5C\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u60A8\\u6709\\u591A\\u4E2A\\u5F02\\u6B65\\u64CD\\u4F5C\\uFF0C\\u5219\\u53EF\\u4EE5\\u5D4C\\u5957 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u5757\\u4EE5\\u5904\\u7406\\u4E0D\\u540C\\u7EA7\\u522B\\u7684\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nasync function processData() {\n try {\n await fetchData();\n // Additional processing\n console.log(arr); // Trying to reference an undefined variable will throw an error\n } catch (error) {\n console.error('Error processing data:', error);\n }\n}\n\nprocessData();\n`})}),`\n`,(0,n.jsxs)(e.h2,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u548C Promises\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u57FA\\u672C\\u7528\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 Promises \\u65F6\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u65B9\\u6CD5\\u5904\\u7406\\u9519\\u8BEF\\u3002\\u5982\\u679C Promise \\u88AB\\u62D2\\u7EDD\\uFF0C\\u5219\\u4F1A\\u8C03\\u7528\\u6B64\\u65B9\\u6CD5\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data')\n .then((response) => response.json())\n .then((data) => console.log(data))\n .catch((error) => console.error('Error fetching data:', error));\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u94FE\\u63A5\\u591A\\u4E2A Promises\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u60A8\\u5C06\\u591A\\u4E2A Promises \\u94FE\\u63A5\\u5728\\u4E00\\u8D77\\uFF0C\\u60A8\\u53EF\\u4EE5\\u5728\\u672B\\u5C3E\\u4F7F\\u7528\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u6765\\u5904\\u7406\\u4EFB\\u4F55 Promise \\u4E2D\\u53D1\\u751F\\u7684\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data')\n .then((response) => response.json())\n .then((data) => {\n // Process data\n return processData(data);\n })\n .then((result) => {\n // Further processing\n console.log(result);\n })\n .catch((error) => console.error('Error in the chain:', error));\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await\",children:\"MDN Web Docs: async/await\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises\",children:\"MDN Web Docs: Promises\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://javascript.info/promise-error-handling\",children:\"JavaScript.info: Error handling with promises\"})}),`\n`]})]})}function D(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(l,r)})):l(r)}var x=D;return w(E);})();\n;return Component;"
+ "solution": "var Component=(()=>{var d=Object.create;var t=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var g=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),y=(r,e)=>{for(var c in e)t(r,c,{get:e[c],enumerable:!0})},s=(r,e,c,o)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of m(e))!f.call(r,a)&&a!==c&&t(r,a,{get:()=>e[a],enumerable:!(o=p(e,a))||o.enumerable});return r};var j=(r,e,c)=>(c=r!=null?d(u(r)):{},s(e||!r||!r.__esModule?t(c,\"default\",{value:r,enumerable:!0}):c,r)),w=r=>s(t({},\"__esModule\",{value:!0}),r);var h=g((U,i)=>{i.exports=_jsx_runtime});var D={};y(D,{default:()=>x,frontmatter:()=>v});var n=j(h()),v={title:\"\\u5982\\u4F55\\u5904\\u7406\\u5F02\\u6B65\\u64CD\\u4F5C\\u4E2D\\u7684\\u9519\\u8BEF\\uFF1F\"};function l(r){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",ul:\"ul\",li:\"li\",a:\"a\"},r.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u8981\\u5904\\u7406\\u5F02\\u6B65\\u64CD\\u4F5C\\u4E2D\\u7684\\u9519\\u8BEF\\uFF0C\\u53EF\\u4EE5\\u4F7F\\u7528\\u5E26\\u6709 \",(0,n.jsx)(e.code,{children:\"async/await\"}),\" \\u8BED\\u6CD5\\u7684 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u5757\\u6216\\u5E26\\u6709 Promises \\u7684 \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u65B9\\u6CD5\\u3002\\u4F8B\\u5982\\uFF0C\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"async/await\"}),\"\\uFF0C\\u60A8\\u53EF\\u4EE5\\u5C06\\u4EE3\\u7801\\u5305\\u88C5\\u5728 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u5757\\u4E2D\\u4EE5\\u6355\\u83B7\\u4EFB\\u4F55\\u9519\\u8BEF\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nfetchData(); // Error fetching data: ....\n`})}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 Promises\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u65B9\\u6CD5\\uFF1A\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data') // Invalid URl\n .then((response) => response.json())\n .then((data) => console.log(data))\n .catch((error) => console.error('Error fetching data:', error));\n`})}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsxs)(e.h2,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u548C \",(0,n.jsx)(e.code,{children:\"async/await\"})]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u57FA\\u672C\\u7528\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\"async/await\"}),\" \\u65F6\\uFF0C\\u60A8\\u53EF\\u4EE5\\u901A\\u8FC7\\u5C06\\u5F02\\u6B65\\u4EE3\\u7801\\u5305\\u88C5\\u5728 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u5757\\u4E2D\\u6765\\u5904\\u7406\\u9519\\u8BEF\\u3002\\u8FD9\\u5141\\u8BB8\\u60A8\\u6355\\u83B7\\u5728\\u6267\\u884C \",(0,n.jsx)(e.code,{children:\"await\"}),\" \\u8BED\\u53E5\\u671F\\u95F4\\u53D1\\u751F\\u7684\\u4EFB\\u4F55\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchData() {\n try {\n // Invalid URl\n const response = await fetch('https://api.example.com/data');\n const data = await response.json();\n console.log(data);\n } catch (error) {\n console.error('Error fetching data:', error);\n }\n}\n\nfetchData(); // Error fetching data: ....\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u5D4C\\u5957\\u5F02\\u6B65\\u64CD\\u4F5C\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u60A8\\u6709\\u591A\\u4E2A\\u5F02\\u6B65\\u64CD\\u4F5C\\uFF0C\\u5219\\u53EF\\u4EE5\\u5D4C\\u5957 \",(0,n.jsx)(e.code,{children:\"try...catch\"}),\" \\u5757\\u4EE5\\u5904\\u7406\\u4E0D\\u540C\\u7EA7\\u522B\\u7684\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`async function fetchUser() {\n // Simulate a successful async operation\n return { id: 1, name: 'Alice' };\n}\n\nasync function fetchUserPosts() {\n // Simulate a failed async operation\n throw new Error('Failed to fetch posts');\n}\n\nasync function loadUserData() {\n try {\n const user = await fetchUser();\n console.log('User:', user);\n\n try {\n const posts = await fetchUserPosts();\n console.log('Posts:', posts);\n } catch (postsError) {\n console.error('Error fetching posts:', postsError.message);\n }\n } catch (userError) {\n console.error('Error fetching user:', userError.message);\n }\n}\n\nloadUserData();\n`})}),`\n`,(0,n.jsxs)(e.h2,{children:[\"\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u548C Promises\"]}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u57FA\\u672C\\u7528\\u6CD5\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u4F7F\\u7528 Promises \\u65F6\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u65B9\\u6CD5\\u5904\\u7406\\u9519\\u8BEF\\u3002\\u5982\\u679C Promise \\u88AB\\u62D2\\u7EDD\\uFF0C\\u5219\\u4F1A\\u8C03\\u7528\\u6B64\\u65B9\\u6CD5\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data')\n .then((response) => response.json())\n .then((data) => console.log(data))\n .catch((error) => console.error('Error fetching data:', error));\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"\\u94FE\\u63A5\\u591A\\u4E2A Promises\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"\\u5982\\u679C\\u60A8\\u5C06\\u591A\\u4E2A Promises \\u94FE\\u63A5\\u5728\\u4E00\\u8D77\\uFF0C\\u60A8\\u53EF\\u4EE5\\u5728\\u672B\\u5C3E\\u4F7F\\u7528\\u4E00\\u4E2A \",(0,n.jsx)(e.code,{children:\".catch()\"}),\" \\u6765\\u5904\\u7406\\u4EFB\\u4F55 Promise \\u4E2D\\u53D1\\u751F\\u7684\\u9519\\u8BEF\\u3002\"]}),`\n`,(0,n.jsx)(e.pre,{live:!0,children:(0,n.jsx)(e.code,{className:\"language-js\",children:`fetch('https://api.example.com/data')\n .then((response) => response.json())\n .then((data) => {\n // Process data\n return processData(data);\n })\n .then((result) => {\n // Further processing\n console.log(result);\n })\n .catch((error) => console.error('Error in the chain:', error));\n`})}),`\n`,(0,n.jsx)(e.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await\",children:\"MDN Web Docs: async/await\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises\",children:\"MDN Web Docs: Promises\"})}),`\n`,(0,n.jsx)(e.li,{children:(0,n.jsx)(e.a,{href:\"https://javascript.info/promise-error-handling\",children:\"JavaScript.info: Error handling with promises\"})}),`\n`]})]})}function E(r={}){let{wrapper:e}=r.components||{};return e?(0,n.jsx)(e,Object.assign({},r,{children:(0,n.jsx)(l,r)})):l(r)}var x=E;return w(D);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-organize-your-code-module-pattern-classical-inheritance/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-do-you-organize-your-code-module-pattern-classical-inheritance/locales/en-US.json
index 2e50664b9..af00e8b4f 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-organize-your-code-module-pattern-classical-inheritance/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-organize-your-code-module-pattern-classical-inheritance/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How do you organize your code?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-do-you-organize-your-code-module-pattern-classical-inheritance/en-US.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(t,n)=>()=>(n||t((n={exports:{}}).exports,n),n.exports),b=(t,n)=>{for(var i in n)o(t,i,{get:n[i],enumerable:!0})},c=(t,n,i,a)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let r of p(n))!g.call(t,r)&&r!==i&&o(t,r,{get:()=>n[r],enumerable:!(a=u(n,r))||a.enumerable});return t};var y=(t,n,i)=>(i=t!=null?h(m(t)):{},c(n||!t||!t.__esModule?o(i,\"default\",{value:t,enumerable:!0}):i,t)),j=t=>c(o({},\"__esModule\",{value:!0}),t);var d=f((I,s)=>{s.exports=_jsx_runtime});var C={};b(C,{default:()=>x,frontmatter:()=>v});var e=y(d()),v={title:\"How do you organize your code?\",subtitle:\"Do you use module pattern, classical inheritance, something else?\"};function l(t){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",pre:\"pre\",code:\"code\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},t.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"I organize my code by following a modular approach, using a clear folder structure, and adhering to coding standards and best practices. I separate concerns by dividing code into different layers such as components, services, and utilities. I also use naming conventions and documentation to ensure code readability and maintainability.\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"How do you organize your code?\"}),`\n`,(0,e.jsx)(n.h3,{children:\"Modular approach\"}),`\n`,(0,e.jsx)(n.p,{children:\"I follow a modular approach to break down the application into smaller, reusable pieces. This helps in managing the codebase more efficiently and makes it easier to maintain and scale.\"}),`\n`,(0,e.jsx)(n.h3,{children:\"Folder structure\"}),`\n`,(0,e.jsx)(n.p,{children:\"I use a clear and consistent folder structure to organize my code. Here is a common structure for a React project:\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{children:`src/\n|-- components/\n| |-- Header/\n| | |-- Header.js\n| | |-- Header.css\n| |-- Footer/\n| | |-- Footer.js\n| | |-- Footer.css\n|-- services/\n| |-- apiService.js\n|-- utils/\n| |-- helpers.js\n|-- App.js\n|-- index.js\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Separation of concerns\"}),`\n`,(0,e.jsx)(n.p,{children:\"I separate concerns by dividing the code into different layers:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Components\"}),\": UI elements that are reusable and self-contained\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Services\"}),\": Functions that handle data fetching and business logic\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Utilities\"}),\": Helper functions and constants that can be used across the application\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Naming conventions\"}),`\n`,(0,e.jsx)(n.p,{children:\"I use consistent naming conventions to improve code readability:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Files and folders\"}),\": Use camelCase or kebab-case for file and folder names\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Components\"}),\": Use PascalCase for React component names\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Variables and functions\"}),\": Use camelCase for variable and function names\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Documentation\"}),`\n`,(0,e.jsx)(n.p,{children:\"I document my code to make it easier for others (and myself) to understand:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Comments\"}),\": Add comments to explain complex logic or important sections of the code\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"README\"}),\": Include a README file with instructions on how to set up and run the project\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Coding standards and best practices\"}),`\n`,(0,e.jsx)(n.p,{children:\"I adhere to coding standards and best practices to ensure code quality:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Linting\"}),\": Use tools like ESLint to enforce coding standards\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Formatting\"}),\": Use tools like Prettier to maintain consistent code formatting\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Testing\"}),\": Write unit tests and integration tests to ensure code reliability\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/faq-structure.html\",children:\"React Folder Structure\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://github.com/airbnb/javascript\",children:\"JavaScript Coding Standards\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://www.freecodecamp.org/news/writing-clean-code-6a8e2889b9f8/\",children:\"Writing Clean Code\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://jsdoc.app/\",children:\"Effective JavaScript Documentation\"})}),`\n`]})]})}function w(t={}){let{wrapper:n}=t.components||{};return n?(0,e.jsx)(n,Object.assign({},t,{children:(0,e.jsx)(l,t)})):l(t)}var x=w;return j(C);})();\n;return Component;"
+ "solution": "var Component=(()=>{var h=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var f=(i,n)=>()=>(n||i((n={exports:{}}).exports,n),n.exports),b=(i,n)=>{for(var t in n)o(i,t,{get:n[t],enumerable:!0})},c=(i,n,t,a)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let r of p(n))!g.call(i,r)&&r!==t&&o(i,r,{get:()=>n[r],enumerable:!(a=u(n,r))||a.enumerable});return i};var y=(i,n,t)=>(t=i!=null?h(m(i)):{},c(n||!i||!i.__esModule?o(t,\"default\",{value:i,enumerable:!0}):t,i)),j=i=>c(o({},\"__esModule\",{value:!0}),i);var d=f((F,s)=>{s.exports=_jsx_runtime});var C={};b(C,{default:()=>x,frontmatter:()=>v});var e=y(d()),v={title:\"How do you organize your code?\",subtitle:\"Do you use module pattern, classical inheritance, something else?\"};function l(i){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",pre:\"pre\",code:\"code\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},i.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"I organize my code by following a modular approach, using a clear folder structure, and adhering to coding standards and best practices. I separate concerns by dividing code into different layers such as components, services, and utilities. I also use naming conventions and documentation to ensure code readability and maintainability.\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"How do you organize your code?\"}),`\n`,(0,e.jsx)(n.h3,{children:\"Modular approach\"}),`\n`,(0,e.jsx)(n.p,{children:\"I follow a modular approach to break down the application into smaller, reusable pieces. This helps in managing the codebase more efficiently and makes it easier to maintain and scale.\"}),`\n`,(0,e.jsx)(n.h3,{children:\"Folder structure\"}),`\n`,(0,e.jsx)(n.p,{children:\"I use a clear and consistent folder structure to organize my code. Here is a common structure for a React project:\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{children:`src/\n|-- components/\n| |-- Header/\n| | |-- Header.js\n| | |-- Header.css\n| |-- Footer/\n| | |-- Footer.js\n| | |-- Footer.css\n|-- services/\n| |-- apiService.js\n|-- utils/\n| |-- helpers.js\n|-- App.js\n|-- index.js\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"Separation of concerns\"}),`\n`,(0,e.jsx)(n.p,{children:\"I separate concerns by dividing the code into different layers:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Components\"}),\": UI elements that are reusable and self-contained\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Services\"}),\": Functions that handle data fetching and business logic\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Utilities\"}),\": Helper functions and constants that can be used across the application\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Naming conventions\"}),`\n`,(0,e.jsx)(n.p,{children:\"I use consistent naming conventions to improve code readability:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Files and folders\"}),\": Use camelCase or kebab-case for file and folder names\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Components\"}),\": Use PascalCase for React component names\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Variables and functions\"}),\": Use camelCase for variable and function names\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Documentation\"}),`\n`,(0,e.jsx)(n.p,{children:\"I document my code to make it easier for others (and myself) to understand:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Comments\"}),\": Add comments to explain complex logic or important sections of the code\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"README\"}),\": Include a README file with instructions on how to set up and run the project\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"Coding standards and best practices\"}),`\n`,(0,e.jsx)(n.p,{children:\"I adhere to coding standards and best practices to ensure code quality:\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Linting\"}),\": Use tools like ESLint to enforce coding standards\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Formatting\"}),\": Use tools like Prettier to maintain consistent code formatting\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Testing\"}),\": Write unit tests and integration tests to ensure code reliability\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://github.com/airbnb/javascript\",children:\"JavaScript Coding Standards\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://www.freecodecamp.org/news/writing-clean-code-6a8e2889b9f8/\",children:\"Writing Clean Code\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://jsdoc.app/\",children:\"Effective JavaScript Documentation\"})}),`\n`]})]})}function w(i={}){let{wrapper:n}=i.components||{};return n?(0,e.jsx)(n,Object.assign({},i,{children:(0,e.jsx)(l,i)})):l(i)}var x=w;return j(C);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-organize-your-code-module-pattern-classical-inheritance/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/how-do-you-organize-your-code-module-pattern-classical-inheritance/locales/zh-CN.json
index 0e4a47c44..d463849dd 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-organize-your-code-module-pattern-classical-inheritance/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-organize-your-code-module-pattern-classical-inheritance/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "你如何组织你的代码?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-do-you-organize-your-code-module-pattern-classical-inheritance/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var a=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var m=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),f=(r,n)=>{for(var i in n)l(r,i,{get:n[i],enumerable:!0})},t=(r,n,i,h)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of g(n))!j.call(r,c)&&c!==i&&l(r,c,{get:()=>n[c],enumerable:!(h=p(n,c))||h.enumerable});return r};var x=(r,n,i)=>(i=r!=null?a(u(r)):{},t(n||!r||!r.__esModule?l(i,\"default\",{value:r,enumerable:!0}):i,r)),b=r=>t(l({},\"__esModule\",{value:!0}),r);var s=m((C,d)=>{d.exports=_jsx_runtime});var R={};f(R,{default:()=>F,frontmatter:()=>_});var e=x(s()),_={title:\"\\u4F60\\u5982\\u4F55\\u7EC4\\u7EC7\\u4F60\\u7684\\u4EE3\\u7801\\uFF1F\",subtitle:\"\\u4F60\\u4F7F\\u7528\\u6A21\\u5757\\u6A21\\u5F0F\\u3001\\u7ECF\\u5178\\u7EE7\\u627F\\u8FD8\\u662F\\u5176\\u4ED6\\u65B9\\u5F0F\\uFF1F\"};function o(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",pre:\"pre\",code:\"code\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u901A\\u8FC7\\u9075\\u5FAA\\u6A21\\u5757\\u5316\\u65B9\\u6CD5\\u3001\\u4F7F\\u7528\\u6E05\\u6670\\u7684\\u6587\\u4EF6\\u5939\\u7ED3\\u6784\\u4EE5\\u53CA\\u9075\\u5B88\\u7F16\\u7801\\u6807\\u51C6\\u548C\\u6700\\u4F73\\u5B9E\\u8DF5\\u6765\\u7EC4\\u7EC7\\u6211\\u7684\\u4EE3\\u7801\\u3002\\u6211\\u901A\\u8FC7\\u5C06\\u4EE3\\u7801\\u5212\\u5206\\u4E3A\\u4E0D\\u540C\\u7684\\u5C42\\uFF08\\u5982\\u7EC4\\u4EF6\\u3001\\u670D\\u52A1\\u548C\\u5B9E\\u7528\\u7A0B\\u5E8F\\uFF09\\u6765\\u5206\\u79BB\\u5173\\u6CE8\\u70B9\\u3002\\u6211\\u8FD8\\u4F7F\\u7528\\u547D\\u540D\\u7EA6\\u5B9A\\u548C\\u6587\\u6863\\u6765\\u786E\\u4FDD\\u4EE3\\u7801\\u7684\\u53EF\\u8BFB\\u6027\\u548C\\u53EF\\u7EF4\\u62A4\\u6027\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4F60\\u5982\\u4F55\\u7EC4\\u7EC7\\u4F60\\u7684\\u4EE3\\u7801\\uFF1F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6A21\\u5757\\u5316\\u65B9\\u6CD5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u9075\\u5FAA\\u6A21\\u5757\\u5316\\u65B9\\u6CD5\\uFF0C\\u5C06\\u5E94\\u7528\\u7A0B\\u5E8F\\u5206\\u89E3\\u4E3A\\u66F4\\u5C0F\\u3001\\u53EF\\u91CD\\u7528\\u7684\\u90E8\\u5206\\u3002\\u8FD9\\u6709\\u52A9\\u4E8E\\u66F4\\u6709\\u6548\\u5730\\u7BA1\\u7406\\u4EE3\\u7801\\u5E93\\uFF0C\\u5E76\\u4F7F\\u5176\\u66F4\\u6613\\u4E8E\\u7EF4\\u62A4\\u548C\\u6269\\u5C55\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6587\\u4EF6\\u5939\\u7ED3\\u6784\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u4F7F\\u7528\\u6E05\\u6670\\u4E00\\u81F4\\u7684\\u6587\\u4EF6\\u5939\\u7ED3\\u6784\\u6765\\u7EC4\\u7EC7\\u6211\\u7684\\u4EE3\\u7801\\u3002\\u4EE5\\u4E0B\\u662F React \\u9879\\u76EE\\u7684\\u5E38\\u89C1\\u7ED3\\u6784\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{children:`src/\n|-- components/\n| |-- Header/\n| | |-- Header.js\n| | |-- Header.css\n| |-- Footer/\n| | |-- Footer.js\n| | |-- Footer.css\n|-- services/\n| |-- apiService.js\n|-- utils/\n| |-- helpers.js\n|-- App.js\n|-- index.js\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5173\\u6CE8\\u70B9\\u5206\\u79BB\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u901A\\u8FC7\\u5C06\\u4EE3\\u7801\\u5212\\u5206\\u4E3A\\u4E0D\\u540C\\u7684\\u5C42\\u6765\\u5206\\u79BB\\u5173\\u6CE8\\u70B9\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7EC4\\u4EF6\"}),\"\\uFF1A\\u53EF\\u91CD\\u7528\\u4E14\\u81EA\\u5305\\u542B\\u7684 UI \\u5143\\u7D20\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u670D\\u52A1\"}),\"\\uFF1A\\u5904\\u7406\\u6570\\u636E\\u83B7\\u53D6\\u548C\\u4E1A\\u52A1\\u903B\\u8F91\\u7684\\u51FD\\u6570\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5B9E\\u7528\\u7A0B\\u5E8F\"}),\"\\uFF1A\\u53EF\\u5728\\u6574\\u4E2A\\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u4F7F\\u7528\\u7684\\u8F85\\u52A9\\u51FD\\u6570\\u548C\\u5E38\\u91CF\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u547D\\u540D\\u7EA6\\u5B9A\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u4F7F\\u7528\\u4E00\\u81F4\\u7684\\u547D\\u540D\\u7EA6\\u5B9A\\u6765\\u63D0\\u9AD8\\u4EE3\\u7801\\u53EF\\u8BFB\\u6027\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6587\\u4EF6\\u548C\\u6587\\u4EF6\\u5939\"}),\"\\uFF1A\\u5BF9\\u6587\\u4EF6\\u548C\\u6587\\u4EF6\\u5939\\u540D\\u79F0\\u4F7F\\u7528 camelCase \\u6216 kebab-case\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7EC4\\u4EF6\"}),\"\\uFF1A\\u5BF9 React \\u7EC4\\u4EF6\\u540D\\u79F0\\u4F7F\\u7528 PascalCase\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53D8\\u91CF\\u548C\\u51FD\\u6570\"}),\"\\uFF1A\\u5BF9\\u53D8\\u91CF\\u548C\\u51FD\\u6570\\u540D\\u79F0\\u4F7F\\u7528 camelCase\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6587\\u6863\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u8BB0\\u5F55\\u6211\\u7684\\u4EE3\\u7801\\uFF0C\\u4EE5\\u4FBF\\u5176\\u4ED6\\u4EBA\\uFF08\\u548C\\u6211\\u81EA\\u5DF1\\uFF09\\u66F4\\u5BB9\\u6613\\u7406\\u89E3\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6CE8\\u91CA\"}),\"\\uFF1A\\u6DFB\\u52A0\\u6CE8\\u91CA\\u4EE5\\u89E3\\u91CA\\u590D\\u6742\\u7684\\u903B\\u8F91\\u6216\\u4EE3\\u7801\\u7684\\u91CD\\u8981\\u90E8\\u5206\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"README\"}),\"\\uFF1A\\u5305\\u542B\\u4E00\\u4E2A README \\u6587\\u4EF6\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u6709\\u5173\\u5982\\u4F55\\u8BBE\\u7F6E\\u548C\\u8FD0\\u884C\\u9879\\u76EE\\u7684\\u8BF4\\u660E\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7F16\\u7801\\u6807\\u51C6\\u548C\\u6700\\u4F73\\u5B9E\\u8DF5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u9075\\u5B88\\u7F16\\u7801\\u6807\\u51C6\\u548C\\u6700\\u4F73\\u5B9E\\u8DF5\\uFF0C\\u4EE5\\u786E\\u4FDD\\u4EE3\\u7801\\u8D28\\u91CF\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Linting\"}),\": \\u4F7F\\u7528 ESLint \\u7B49\\u5DE5\\u5177\\u6765\\u6267\\u884C\\u7F16\\u7801\\u6807\\u51C6\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Formatting\"}),\": \\u4F7F\\u7528 Prettier \\u7B49\\u5DE5\\u5177\\u6765\\u4FDD\\u6301\\u4E00\\u81F4\\u7684\\u4EE3\\u7801\\u683C\\u5F0F\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Testing\"}),\": \\u7F16\\u5199\\u5355\\u5143\\u6D4B\\u8BD5\\u548C\\u96C6\\u6210\\u6D4B\\u8BD5\\u4EE5\\u786E\\u4FDD\\u4EE3\\u7801\\u53EF\\u9760\\u6027\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://reactjs.org/docs/faq-structure.html\",children:\"React \\u6587\\u4EF6\\u5939\\u7ED3\\u6784\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://github.com/airbnb/javascript\",children:\"JavaScript \\u7F16\\u7801\\u6807\\u51C6\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://www.freecodecamp.org/news/writing-clean-code-6a8e2889b9f8/\",children:\"\\u7F16\\u5199\\u5E72\\u51C0\\u7684\\u4EE3\\u7801\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://jsdoc.app/\",children:\"\\u6709\\u6548\\u7684 JavaScript \\u6587\\u6863\"})}),`\n`]})]})}function w(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(o,r)})):o(r)}var F=w;return b(R);})();\n;return Component;"
+ "solution": "var Component=(()=>{var a=Object.create;var l=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,j=Object.prototype.hasOwnProperty;var m=(r,n)=>()=>(n||r((n={exports:{}}).exports,n),n.exports),f=(r,n)=>{for(var i in n)l(r,i,{get:n[i],enumerable:!0})},t=(r,n,i,h)=>{if(n&&typeof n==\"object\"||typeof n==\"function\")for(let c of g(n))!j.call(r,c)&&c!==i&&l(r,c,{get:()=>n[c],enumerable:!(h=p(n,c))||h.enumerable});return r};var x=(r,n,i)=>(i=r!=null?a(u(r)):{},t(n||!r||!r.__esModule?l(i,\"default\",{value:r,enumerable:!0}):i,r)),b=r=>t(l({},\"__esModule\",{value:!0}),r);var s=m((D,d)=>{d.exports=_jsx_runtime});var v={};f(v,{default:()=>F,frontmatter:()=>_});var e=x(s()),_={title:\"\\u4F60\\u5982\\u4F55\\u7EC4\\u7EC7\\u4F60\\u7684\\u4EE3\\u7801\\uFF1F\",subtitle:\"\\u4F60\\u4F7F\\u7528\\u6A21\\u5757\\u6A21\\u5F0F\\u3001\\u7ECF\\u5178\\u7EE7\\u627F\\u8FD8\\u662F\\u5176\\u4ED6\\u65B9\\u5F0F\\uFF1F\"};function o(r){let n=Object.assign({h2:\"h2\",p:\"p\",hr:\"hr\",h3:\"h3\",pre:\"pre\",code:\"code\",ul:\"ul\",li:\"li\",strong:\"strong\",a:\"a\"},r.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(n.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u901A\\u8FC7\\u9075\\u5FAA\\u6A21\\u5757\\u5316\\u65B9\\u6CD5\\u3001\\u4F7F\\u7528\\u6E05\\u6670\\u7684\\u6587\\u4EF6\\u5939\\u7ED3\\u6784\\u4EE5\\u53CA\\u9075\\u5B88\\u7F16\\u7801\\u6807\\u51C6\\u548C\\u6700\\u4F73\\u5B9E\\u8DF5\\u6765\\u7EC4\\u7EC7\\u6211\\u7684\\u4EE3\\u7801\\u3002\\u6211\\u901A\\u8FC7\\u5C06\\u4EE3\\u7801\\u5212\\u5206\\u4E3A\\u4E0D\\u540C\\u7684\\u5C42\\uFF08\\u5982\\u7EC4\\u4EF6\\u3001\\u670D\\u52A1\\u548C\\u5B9E\\u7528\\u7A0B\\u5E8F\\uFF09\\u6765\\u5206\\u79BB\\u5173\\u6CE8\\u70B9\\u3002\\u6211\\u8FD8\\u4F7F\\u7528\\u547D\\u540D\\u7EA6\\u5B9A\\u548C\\u6587\\u6863\\u6765\\u786E\\u4FDD\\u4EE3\\u7801\\u7684\\u53EF\\u8BFB\\u6027\\u548C\\u53EF\\u7EF4\\u62A4\\u6027\\u3002\"}),`\n`,(0,e.jsx)(n.hr,{}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u4F60\\u5982\\u4F55\\u7EC4\\u7EC7\\u4F60\\u7684\\u4EE3\\u7801\\uFF1F\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6A21\\u5757\\u5316\\u65B9\\u6CD5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u9075\\u5FAA\\u6A21\\u5757\\u5316\\u65B9\\u6CD5\\uFF0C\\u5C06\\u5E94\\u7528\\u7A0B\\u5E8F\\u5206\\u89E3\\u4E3A\\u66F4\\u5C0F\\u3001\\u53EF\\u91CD\\u7528\\u7684\\u90E8\\u5206\\u3002\\u8FD9\\u6709\\u52A9\\u4E8E\\u66F4\\u6709\\u6548\\u5730\\u7BA1\\u7406\\u4EE3\\u7801\\u5E93\\uFF0C\\u5E76\\u4F7F\\u5176\\u66F4\\u6613\\u4E8E\\u7EF4\\u62A4\\u548C\\u6269\\u5C55\\u3002\"}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6587\\u4EF6\\u5939\\u7ED3\\u6784\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u4F7F\\u7528\\u6E05\\u6670\\u4E00\\u81F4\\u7684\\u6587\\u4EF6\\u5939\\u7ED3\\u6784\\u6765\\u7EC4\\u7EC7\\u6211\\u7684\\u4EE3\\u7801\\u3002\\u4EE5\\u4E0B\\u662F React \\u9879\\u76EE\\u7684\\u5E38\\u89C1\\u7ED3\\u6784\\uFF1A\"}),`\n`,(0,e.jsx)(n.pre,{children:(0,e.jsx)(n.code,{children:`src/\n|-- components/\n| |-- Header/\n| | |-- Header.js\n| | |-- Header.css\n| |-- Footer/\n| | |-- Footer.js\n| | |-- Footer.css\n|-- services/\n| |-- apiService.js\n|-- utils/\n| |-- helpers.js\n|-- App.js\n|-- index.js\n`})}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u5173\\u6CE8\\u70B9\\u5206\\u79BB\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u901A\\u8FC7\\u5C06\\u4EE3\\u7801\\u5212\\u5206\\u4E3A\\u4E0D\\u540C\\u7684\\u5C42\\u6765\\u5206\\u79BB\\u5173\\u6CE8\\u70B9\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7EC4\\u4EF6\"}),\"\\uFF1A\\u53EF\\u91CD\\u7528\\u4E14\\u81EA\\u5305\\u542B\\u7684 UI \\u5143\\u7D20\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u670D\\u52A1\"}),\"\\uFF1A\\u5904\\u7406\\u6570\\u636E\\u83B7\\u53D6\\u548C\\u4E1A\\u52A1\\u903B\\u8F91\\u7684\\u51FD\\u6570\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u5B9E\\u7528\\u7A0B\\u5E8F\"}),\"\\uFF1A\\u53EF\\u5728\\u6574\\u4E2A\\u5E94\\u7528\\u7A0B\\u5E8F\\u4E2D\\u4F7F\\u7528\\u7684\\u8F85\\u52A9\\u51FD\\u6570\\u548C\\u5E38\\u91CF\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u547D\\u540D\\u7EA6\\u5B9A\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u4F7F\\u7528\\u4E00\\u81F4\\u7684\\u547D\\u540D\\u7EA6\\u5B9A\\u6765\\u63D0\\u9AD8\\u4EE3\\u7801\\u53EF\\u8BFB\\u6027\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6587\\u4EF6\\u548C\\u6587\\u4EF6\\u5939\"}),\"\\uFF1A\\u5BF9\\u6587\\u4EF6\\u548C\\u6587\\u4EF6\\u5939\\u540D\\u79F0\\u4F7F\\u7528 camelCase \\u6216 kebab-case\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u7EC4\\u4EF6\"}),\"\\uFF1A\\u5BF9 React \\u7EC4\\u4EF6\\u540D\\u79F0\\u4F7F\\u7528 PascalCase\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u53D8\\u91CF\\u548C\\u51FD\\u6570\"}),\"\\uFF1A\\u5BF9\\u53D8\\u91CF\\u548C\\u51FD\\u6570\\u540D\\u79F0\\u4F7F\\u7528 camelCase\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u6587\\u6863\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u8BB0\\u5F55\\u6211\\u7684\\u4EE3\\u7801\\uFF0C\\u4EE5\\u4FBF\\u5176\\u4ED6\\u4EBA\\uFF08\\u548C\\u6211\\u81EA\\u5DF1\\uFF09\\u66F4\\u5BB9\\u6613\\u7406\\u89E3\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"\\u6CE8\\u91CA\"}),\"\\uFF1A\\u6DFB\\u52A0\\u6CE8\\u91CA\\u4EE5\\u89E3\\u91CA\\u590D\\u6742\\u7684\\u903B\\u8F91\\u6216\\u4EE3\\u7801\\u7684\\u91CD\\u8981\\u90E8\\u5206\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"README\"}),\"\\uFF1A\\u5305\\u542B\\u4E00\\u4E2A README \\u6587\\u4EF6\\uFF0C\\u5176\\u4E2D\\u5305\\u542B\\u6709\\u5173\\u5982\\u4F55\\u8BBE\\u7F6E\\u548C\\u8FD0\\u884C\\u9879\\u76EE\\u7684\\u8BF4\\u660E\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h3,{children:\"\\u7F16\\u7801\\u6807\\u51C6\\u548C\\u6700\\u4F73\\u5B9E\\u8DF5\"}),`\n`,(0,e.jsx)(n.p,{children:\"\\u6211\\u9075\\u5B88\\u7F16\\u7801\\u6807\\u51C6\\u548C\\u6700\\u4F73\\u5B9E\\u8DF5\\uFF0C\\u4EE5\\u786E\\u4FDD\\u4EE3\\u7801\\u8D28\\u91CF\\uFF1A\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Linting\"}),\": \\u4F7F\\u7528 ESLint \\u7B49\\u5DE5\\u5177\\u6765\\u6267\\u884C\\u7F16\\u7801\\u6807\\u51C6\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Formatting\"}),\": \\u4F7F\\u7528 Prettier \\u7B49\\u5DE5\\u5177\\u6765\\u4FDD\\u6301\\u4E00\\u81F4\\u7684\\u4EE3\\u7801\\u683C\\u5F0F\"]}),`\n`,(0,e.jsxs)(n.li,{children:[(0,e.jsx)(n.strong,{children:\"Testing\"}),\": \\u7F16\\u5199\\u5355\\u5143\\u6D4B\\u8BD5\\u548C\\u96C6\\u6210\\u6D4B\\u8BD5\\u4EE5\\u786E\\u4FDD\\u4EE3\\u7801\\u53EF\\u9760\\u6027\"]}),`\n`]}),`\n`,(0,e.jsx)(n.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(n.ul,{children:[`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://github.com/airbnb/javascript\",children:\"JavaScript \\u7F16\\u7801\\u89C4\\u8303\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://www.freecodecamp.org/news/writing-clean-code-6a8e2889b9f8/\",children:\"\\u7F16\\u5199\\u5E72\\u51C0\\u7684\\u4EE3\\u7801\"})}),`\n`,(0,e.jsx)(n.li,{children:(0,e.jsx)(n.a,{href:\"https://jsdoc.app/\",children:\"\\u6709\\u6548\\u7684 JavaScript \\u6587\\u6863\"})}),`\n`]})]})}function w(r={}){let{wrapper:n}=r.components||{};return n?(0,e.jsx)(n,Object.assign({},r,{children:(0,e.jsx)(o,r)})):o(r)}var F=w;return b(v);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-reset-a-components-state-in-react/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-do-you-reset-a-components-state-in-react/locales/en-US.json
index 0c8949d88..3ad3e160d 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-reset-a-components-state-in-react/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-reset-a-components-state-in-react/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How do you reset a component's state in React?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/how-do-you-reset-a-components-state-in-react/en-US.mdx"
},
- "solution": "var Component=(()=>{var p=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var g=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),x=(n,t)=>{for(var a in t)s(n,a,{get:t[a],enumerable:!0})},c=(n,t,a,o)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let i of u(t))!S.call(n,i)&&i!==a&&s(n,i,{get:()=>t[i],enumerable:!(o=d(t,i))||o.enumerable});return n};var f=(n,t,a)=>(a=n!=null?p(m(n)):{},c(t||!n||!n.__esModule?s(a,\"default\",{value:n,enumerable:!0}):a,n)),y=n=>c(s({},\"__esModule\",{value:!0}),n);var l=g((k,r)=>{r.exports=_jsx_runtime});var b={};x(b,{default:()=>v,frontmatter:()=>C});var e=f(l()),C={title:\"How do you reset a component's state in React?\"};function h(n){let t=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},n.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(t.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"To reset a component's state in React, you can set the state back to its initial value. This can be done by defining an initial state and then using the \",(0,e.jsx)(t.code,{children:\"setState\"}),\" function to reset it. For example, if you have a state object like this:\"]}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`const [state, setState] = useState(initialState);\n`})}),`\n`,(0,e.jsx)(t.p,{children:\"You can reset it by calling:\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`setState(initialState);\n`})}),`\n`,(0,e.jsx)(t.hr,{}),`\n`,(0,e.jsx)(t.h2,{children:\"How do you reset a component's state in React?\"}),`\n`,(0,e.jsx)(t.h3,{children:\"Using functional components with hooks\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"In functional components, you can use the \",(0,e.jsx)(t.code,{children:\"useState\"}),\" hook to manage state. To reset the state, you can simply call the \",(0,e.jsx)(t.code,{children:\"setState\"}),\" function with the initial state value.\"]}),`\n`,(0,e.jsx)(t.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { useState } from 'react';\n\nconst MyComponent = () => {\n const initialState = { count: 0, text: '' };\n const [state, setState] = useState(initialState);\n\n const resetState = () => {\n setState(initialState);\n };\n\n return (\n \n
Count: {state.count}
\n
Text: {state.text}
\n
Reset \n
\n );\n};\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h3,{children:\"Using class components\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"In class components, you can reset the state by calling \",(0,e.jsx)(t.code,{children:\"this.setState\"}),\" with the initial state value.\"]}),`\n`,(0,e.jsx)(t.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { Component } from 'react';\n\nclass MyComponent extends Component {\n constructor(props) {\n super(props);\n this.initialState = { count: 0, text: '' };\n this.state = this.initialState;\n }\n\n resetState = () => {\n this.setState(this.initialState);\n };\n\n render() {\n return (\n \n
Count: {this.state.count}
\n
Text: {this.state.text}
\n
Reset \n
\n );\n }\n}\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h3,{children:\"Using a function to generate initial state\"}),`\n`,(0,e.jsx)(t.p,{children:\"Sometimes, the initial state might be derived from props or other dynamic sources. In such cases, you can use a function to generate the initial state.\"}),`\n`,(0,e.jsx)(t.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { useState } from 'react';\n\nconst MyComponent = (props) => {\n const getInitialState = () => ({ count: props.initialCount, text: '' });\n const [state, setState] = useState(getInitialState);\n\n const resetState = () => {\n setState(getInitialState());\n };\n\n return (\n \n
Count: {state.count}
\n
Text: {state.text}
\n
Reset \n
\n );\n};\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(t.ul,{children:[`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://reactjs.org/docs/hooks-state.html\",children:\"React useState Hook\"})}),`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://reactjs.org/docs/state-and-lifecycle.html\",children:\"React Component State\"})}),`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://reactjs.org/docs/components-and-props.html#function-and-class-components\",children:\"React Functional Components\"})}),`\n`]})]})}function j(n={}){let{wrapper:t}=n.components||{};return t?(0,e.jsx)(t,Object.assign({},n,{children:(0,e.jsx)(h,n)})):h(n)}var v=j;return y(b);})();\n;return Component;"
+ "solution": "var Component=(()=>{var p=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var g=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),x=(n,t)=>{for(var a in t)s(n,a,{get:t[a],enumerable:!0})},c=(n,t,a,o)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let i of u(t))!S.call(n,i)&&i!==a&&s(n,i,{get:()=>t[i],enumerable:!(o=d(t,i))||o.enumerable});return n};var f=(n,t,a)=>(a=n!=null?p(m(n)):{},c(t||!n||!n.__esModule?s(a,\"default\",{value:n,enumerable:!0}):a,n)),y=n=>c(s({},\"__esModule\",{value:!0}),n);var l=g((M,r)=>{r.exports=_jsx_runtime});var j={};x(j,{default:()=>b,frontmatter:()=>C});var e=f(l()),C={title:\"How do you reset a component's state in React?\"};function h(n){let t=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},n.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(t.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"To reset a component's state in React, you can set the state back to its initial value. This can be done by defining an initial state and then using the \",(0,e.jsx)(t.code,{children:\"setState\"}),\" function to reset it. For example, if you have a state object like this:\"]}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`const [state, setState] = useState(initialState);\n`})}),`\n`,(0,e.jsx)(t.p,{children:\"You can reset it by calling:\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`setState(initialState);\n`})}),`\n`,(0,e.jsx)(t.hr,{}),`\n`,(0,e.jsx)(t.h2,{children:\"How do you reset a component's state in React?\"}),`\n`,(0,e.jsx)(t.h3,{children:\"Using functional components with hooks\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"In functional components, you can use the \",(0,e.jsx)(t.code,{children:\"useState\"}),\" hook to manage state. To reset the state, you can simply call the \",(0,e.jsx)(t.code,{children:\"setState\"}),\" function with the initial state value.\"]}),`\n`,(0,e.jsx)(t.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { useState } from 'react';\n\nconst MyComponent = () => {\n const initialState = { count: 0, text: '' };\n const [state, setState] = useState(initialState);\n\n const resetState = () => {\n setState(initialState);\n };\n\n return (\n \n
Count: {state.count}
\n
Text: {state.text}
\n
Reset \n
\n );\n};\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h3,{children:\"Using class components\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"In class components, you can reset the state by calling \",(0,e.jsx)(t.code,{children:\"this.setState\"}),\" with the initial state value.\"]}),`\n`,(0,e.jsx)(t.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { Component } from 'react';\n\nclass MyComponent extends Component {\n constructor(props) {\n super(props);\n this.initialState = { count: 0, text: '' };\n this.state = this.initialState;\n }\n\n resetState = () => {\n this.setState(this.initialState);\n };\n\n render() {\n return (\n \n
Count: {this.state.count}
\n
Text: {this.state.text}
\n
Reset \n
\n );\n }\n}\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h3,{children:\"Using a function to generate initial state\"}),`\n`,(0,e.jsx)(t.p,{children:\"Sometimes, the initial state might be derived from props or other dynamic sources. In such cases, you can use a function to generate the initial state.\"}),`\n`,(0,e.jsx)(t.h4,{children:\"Example\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { useState } from 'react';\n\nconst MyComponent = (props) => {\n const getInitialState = () => ({ count: props.initialCount, text: '' });\n const [state, setState] = useState(getInitialState);\n\n const resetState = () => {\n setState(getInitialState());\n };\n\n return (\n \n
Count: {state.count}
\n
Text: {state.text}
\n
Reset \n
\n );\n};\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h2,{children:\"Further reading\"}),`\n`,(0,e.jsxs)(t.ul,{children:[`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://react.dev/reference/react/useState\",children:\"React useState Hook\"})}),`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://react.dev/learn/state-a-components-memory\",children:\"React Component State\"})}),`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://react.dev/reference/react/Component\",children:\"React Functional Components\"})}),`\n`]})]})}function v(n={}){let{wrapper:t}=n.components||{};return t?(0,e.jsx)(t,Object.assign({},n,{children:(0,e.jsx)(h,n)})):h(n)}var b=v;return y(j);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-reset-a-components-state-in-react/locales/zh-CN.json b/apps/web/src/__generated__/questions/quiz/how-do-you-reset-a-components-state-in-react/locales/zh-CN.json
index 455deabaa..d482ff59d 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-reset-a-components-state-in-react/locales/zh-CN.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-reset-a-components-state-in-react/locales/zh-CN.json
@@ -5,5 +5,5 @@
"title": "如何在 React 中重置组件的状态?",
"gitHubEditUrl": "https://github.com/yangshun/top-reactjs-interview-questions/blob/main/questions/how-do-you-reset-a-components-state-in-react/zh-CN.mdx"
},
- "solution": "var Component=(()=>{var p=Object.create;var s=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var m=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var x=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),g=(e,t)=>{for(var a in t)s(e,a,{get:t[a],enumerable:!0})},r=(e,t,a,i)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let c of u(t))!S.call(e,c)&&c!==a&&s(e,c,{get:()=>t[c],enumerable:!(i=d(t,c))||i.enumerable});return e};var C=(e,t,a)=>(a=e!=null?p(m(e)):{},r(t||!e||!e.__esModule?s(a,\"default\",{value:e,enumerable:!0}):a,e)),f=e=>r(s({},\"__esModule\",{value:!0}),e);var l=x((y,o)=>{o.exports=_jsx_runtime});var M={};g(M,{default:()=>v,frontmatter:()=>j});var n=C(l()),j={title:\"\\u5982\\u4F55\\u5728 React \\u4E2D\\u91CD\\u7F6E\\u7EC4\\u4EF6\\u7684\\u72B6\\u6001\\uFF1F\"};function h(e){let t=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},e.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(t.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(t.p,{children:[\"\\u8981\\u5728 React \\u4E2D\\u91CD\\u7F6E\\u7EC4\\u4EF6\\u7684\\u72B6\\u6001\\uFF0C\\u60A8\\u53EF\\u4EE5\\u5C06\\u72B6\\u6001\\u8BBE\\u7F6E\\u56DE\\u5176\\u521D\\u59CB\\u503C\\u3002\\u8FD9\\u53EF\\u4EE5\\u901A\\u8FC7\\u5B9A\\u4E49\\u521D\\u59CB\\u72B6\\u6001\\uFF0C\\u7136\\u540E\\u4F7F\\u7528 \",(0,n.jsx)(t.code,{children:\"setState\"}),\" \\u51FD\\u6570\\u6765\\u91CD\\u7F6E\\u5B83\\u6765\\u5B9E\\u73B0\\u3002\\u4F8B\\u5982\\uFF0C\\u5982\\u679C\\u60A8\\u6709\\u4E00\\u4E2A\\u50CF\\u8FD9\\u6837\\u7684\\u72B6\\u6001\\u5BF9\\u8C61\\uFF1A\"]}),`\n`,(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:\"language-javascript\",children:`const [state, setState] = useState(initialState);\n`})}),`\n`,(0,n.jsx)(t.p,{children:\"\\u60A8\\u53EF\\u4EE5\\u901A\\u8FC7\\u8C03\\u7528\\u4EE5\\u4E0B\\u65B9\\u6CD5\\u6765\\u91CD\\u7F6E\\u5B83\\uFF1A\"}),`\n`,(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:\"language-javascript\",children:`setState(initialState);\n`})}),`\n`,(0,n.jsx)(t.hr,{}),`\n`,(0,n.jsx)(t.h2,{children:\"\\u5982\\u4F55\\u5728 React \\u4E2D\\u91CD\\u7F6E\\u7EC4\\u4EF6\\u7684\\u72B6\\u6001\\uFF1F\"}),`\n`,(0,n.jsx)(t.h3,{children:\"\\u4F7F\\u7528\\u5E26\\u6709\\u94A9\\u5B50\\u7684\\u51FD\\u6570\\u5F0F\\u7EC4\\u4EF6\"}),`\n`,(0,n.jsxs)(t.p,{children:[\"\\u5728\\u51FD\\u6570\\u5F0F\\u7EC4\\u4EF6\\u4E2D\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,n.jsx)(t.code,{children:\"useState\"}),\" \\u94A9\\u5B50\\u6765\\u7BA1\\u7406\\u72B6\\u6001\\u3002\\u8981\\u91CD\\u7F6E\\u72B6\\u6001\\uFF0C\\u60A8\\u53EF\\u4EE5\\u7B80\\u5355\\u5730\\u4F7F\\u7528\\u521D\\u59CB\\u72B6\\u6001\\u503C\\u8C03\\u7528 \",(0,n.jsx)(t.code,{children:\"setState\"}),\" \\u51FD\\u6570\\u3002\"]}),`\n`,(0,n.jsx)(t.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:\"language-javascript\",children:`import React, { useState } from 'react';\n\nconst MyComponent = () => {\n const initialState = { count: 0, text: '' };\n const [state, setState] = useState(initialState);\n\n const resetState = () => {\n setState(initialState);\n };\n\n return (\n \n
Count: {state.count}
\n
Text: {state.text}
\n
Reset \n
\n );\n};\n\nexport default MyComponent;\n`})}),`\n`,(0,n.jsx)(t.h3,{children:\"\\u4F7F\\u7528\\u7C7B\\u7EC4\\u4EF6\"}),`\n`,(0,n.jsxs)(t.p,{children:[\"\\u5728\\u7C7B\\u7EC4\\u4EF6\\u4E2D\\uFF0C\\u60A8\\u53EF\\u4EE5\\u901A\\u8FC7\\u4F7F\\u7528\\u521D\\u59CB\\u72B6\\u6001\\u503C\\u8C03\\u7528 \",(0,n.jsx)(t.code,{children:\"this.setState\"}),\" \\u6765\\u91CD\\u7F6E\\u72B6\\u6001\\u3002\"]}),`\n`,(0,n.jsx)(t.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:\"language-javascript\",children:`import React, { Component } from 'react';\n\nclass MyComponent extends Component {\n constructor(props) {\n super(props);\n this.initialState = { count: 0, text: '' };\n this.state = this.initialState;\n }\n\n resetState = () => {\n this.setState(this.initialState);\n };\n\n render() {\n return (\n \n
Count: {this.state.count}
\n
Text: {this.state.text}
\n
Reset \n
\n );\n }\n}\n\nexport default MyComponent;\n`})}),`\n`,(0,n.jsx)(t.h3,{children:\"\\u4F7F\\u7528\\u51FD\\u6570\\u751F\\u6210\\u521D\\u59CB\\u72B6\\u6001\"}),`\n`,(0,n.jsx)(t.p,{children:\"\\u6709\\u65F6\\uFF0C\\u521D\\u59CB\\u72B6\\u6001\\u53EF\\u80FD\\u6E90\\u81EA props \\u6216\\u5176\\u4ED6\\u52A8\\u6001\\u6E90\\u3002\\u5728\\u8FD9\\u79CD\\u60C5\\u51B5\\u4E0B\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u751F\\u6210\\u521D\\u59CB\\u72B6\\u6001\\u3002\"}),`\n`,(0,n.jsx)(t.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,n.jsx)(t.pre,{children:(0,n.jsx)(t.code,{className:\"language-javascript\",children:`import React, { useState } from 'react';\n\nconst MyComponent = (props) => {\n const getInitialState = () => ({ count: props.initialCount, text: '' });\n const [state, setState] = useState(getInitialState);\n\n const resetState = () => {\n setState(getInitialState());\n };\n\n return (\n \n
Count: {state.count}
\n
Text: {state.text}
\n
Reset \n
\n );\n};\n\nexport default MyComponent;\n`})}),`\n`,(0,n.jsx)(t.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,n.jsxs)(t.ul,{children:[`\n`,(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:\"https://reactjs.org/docs/hooks-state.html\",children:\"React useState Hook\"})}),`\n`,(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:\"https://reactjs.org/docs/state-and-lifecycle.html\",children:\"React Component State\"})}),`\n`,(0,n.jsx)(t.li,{children:(0,n.jsx)(t.a,{href:\"https://reactjs.org/docs/components-and-props.html#function-and-class-components\",children:\"React Functional Components\"})}),`\n`]})]})}function R(e={}){let{wrapper:t}=e.components||{};return t?(0,n.jsx)(t,Object.assign({},e,{children:(0,n.jsx)(h,e)})):h(e)}var v=R;return f(M);})();\n;return Component;"
+ "solution": "var Component=(()=>{var p=Object.create;var c=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty;var x=(n,t)=>()=>(t||n((t={exports:{}}).exports,t),t.exports),C=(n,t)=>{for(var a in t)c(n,a,{get:t[a],enumerable:!0})},s=(n,t,a,i)=>{if(t&&typeof t==\"object\"||typeof t==\"function\")for(let r of u(t))!m.call(n,r)&&r!==a&&c(n,r,{get:()=>t[r],enumerable:!(i=d(t,r))||i.enumerable});return n};var g=(n,t,a)=>(a=n!=null?p(S(n)):{},s(t||!n||!n.__esModule?c(a,\"default\",{value:n,enumerable:!0}):a,n)),f=n=>s(c({},\"__esModule\",{value:!0}),n);var l=x((y,o)=>{o.exports=_jsx_runtime});var M={};C(M,{default:()=>j,frontmatter:()=>v});var e=g(l()),v={title:\"\\u5982\\u4F55\\u5728 React \\u4E2D\\u91CD\\u7F6E\\u7EC4\\u4EF6\\u7684\\u72B6\\u6001\\uFF1F\"};function h(n){let t=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},n.components);return(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(t.h2,{children:\"TL;DR\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"\\u8981\\u5728 React \\u4E2D\\u91CD\\u7F6E\\u7EC4\\u4EF6\\u7684\\u72B6\\u6001\\uFF0C\\u60A8\\u53EF\\u4EE5\\u5C06\\u72B6\\u6001\\u8BBE\\u7F6E\\u56DE\\u5176\\u521D\\u59CB\\u503C\\u3002\\u8FD9\\u53EF\\u4EE5\\u901A\\u8FC7\\u5B9A\\u4E49\\u521D\\u59CB\\u72B6\\u6001\\uFF0C\\u7136\\u540E\\u4F7F\\u7528 \",(0,e.jsx)(t.code,{children:\"setState\"}),\" \\u51FD\\u6570\\u6765\\u91CD\\u7F6E\\u5B83\\u6765\\u5B9E\\u73B0\\u3002\\u4F8B\\u5982\\uFF0C\\u5982\\u679C\\u60A8\\u6709\\u4E00\\u4E2A\\u50CF\\u8FD9\\u6837\\u7684\\u72B6\\u6001\\u5BF9\\u8C61\\uFF1A\"]}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`const [state, setState] = useState(initialState);\n`})}),`\n`,(0,e.jsx)(t.p,{children:\"\\u60A8\\u53EF\\u4EE5\\u901A\\u8FC7\\u8C03\\u7528\\u4EE5\\u4E0B\\u65B9\\u6CD5\\u6765\\u91CD\\u7F6E\\u5B83\\uFF1A\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`setState(initialState);\n`})}),`\n`,(0,e.jsx)(t.hr,{}),`\n`,(0,e.jsx)(t.h2,{children:\"\\u5982\\u4F55\\u5728 React \\u4E2D\\u91CD\\u7F6E\\u7EC4\\u4EF6\\u7684\\u72B6\\u6001\\uFF1F\"}),`\n`,(0,e.jsx)(t.h3,{children:\"\\u4F7F\\u7528\\u5E26\\u6709\\u94A9\\u5B50\\u7684\\u51FD\\u6570\\u5F0F\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"\\u5728\\u51FD\\u6570\\u5F0F\\u7EC4\\u4EF6\\u4E2D\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528 \",(0,e.jsx)(t.code,{children:\"useState\"}),\" \\u94A9\\u5B50\\u6765\\u7BA1\\u7406\\u72B6\\u6001\\u3002\\u8981\\u91CD\\u7F6E\\u72B6\\u6001\\uFF0C\\u60A8\\u53EF\\u4EE5\\u7B80\\u5355\\u5730\\u4F7F\\u7528\\u521D\\u59CB\\u72B6\\u6001\\u503C\\u8C03\\u7528 \",(0,e.jsx)(t.code,{children:\"setState\"}),\" \\u51FD\\u6570\\u3002\"]}),`\n`,(0,e.jsx)(t.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { useState } from 'react';\n\nconst MyComponent = () => {\n const initialState = { count: 0, text: '' };\n const [state, setState] = useState(initialState);\n\n const resetState = () => {\n setState(initialState);\n };\n\n return (\n \n
Count: {state.count}
\n
Text: {state.text}
\n
Reset \n
\n );\n};\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h3,{children:\"\\u4F7F\\u7528\\u7C7B\\u7EC4\\u4EF6\"}),`\n`,(0,e.jsxs)(t.p,{children:[\"\\u5728\\u7C7B\\u7EC4\\u4EF6\\u4E2D\\uFF0C\\u60A8\\u53EF\\u4EE5\\u901A\\u8FC7\\u4F7F\\u7528\\u521D\\u59CB\\u72B6\\u6001\\u503C\\u8C03\\u7528 \",(0,e.jsx)(t.code,{children:\"this.setState\"}),\" \\u6765\\u91CD\\u7F6E\\u72B6\\u6001\\u3002\"]}),`\n`,(0,e.jsx)(t.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { Component } from 'react';\n\nclass MyComponent extends Component {\n constructor(props) {\n super(props);\n this.initialState = { count: 0, text: '' };\n this.state = this.initialState;\n }\n\n resetState = () => {\n this.setState(this.initialState);\n };\n\n render() {\n return (\n \n
Count: {this.state.count}
\n
Text: {this.state.text}
\n
Reset \n
\n );\n }\n}\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h3,{children:\"\\u4F7F\\u7528\\u51FD\\u6570\\u751F\\u6210\\u521D\\u59CB\\u72B6\\u6001\"}),`\n`,(0,e.jsx)(t.p,{children:\"\\u6709\\u65F6\\uFF0C\\u521D\\u59CB\\u72B6\\u6001\\u53EF\\u80FD\\u6E90\\u81EA props \\u6216\\u5176\\u4ED6\\u52A8\\u6001\\u6E90\\u3002\\u5728\\u8FD9\\u79CD\\u60C5\\u51B5\\u4E0B\\uFF0C\\u60A8\\u53EF\\u4EE5\\u4F7F\\u7528\\u4E00\\u4E2A\\u51FD\\u6570\\u6765\\u751F\\u6210\\u521D\\u59CB\\u72B6\\u6001\\u3002\"}),`\n`,(0,e.jsx)(t.h4,{children:\"\\u793A\\u4F8B\"}),`\n`,(0,e.jsx)(t.pre,{children:(0,e.jsx)(t.code,{className:\"language-javascript\",children:`import React, { useState } from 'react';\n\nconst MyComponent = (props) => {\n const getInitialState = () => ({ count: props.initialCount, text: '' });\n const [state, setState] = useState(getInitialState);\n\n const resetState = () => {\n setState(getInitialState());\n };\n\n return (\n \n
Count: {state.count}
\n
Text: {state.text}
\n
Reset \n
\n );\n};\n\nexport default MyComponent;\n`})}),`\n`,(0,e.jsx)(t.h2,{children:\"\\u5EF6\\u4F38\\u9605\\u8BFB\"}),`\n`,(0,e.jsxs)(t.ul,{children:[`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://react.dev/reference/react/useState\",children:\"React useState Hook\"})}),`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://react.dev/learn/state-a-components-memory\",children:\"React Component State\"})}),`\n`,(0,e.jsx)(t.li,{children:(0,e.jsx)(t.a,{href:\"https://react.dev/reference/react/Component\",children:\"React Functional Components\"})}),`\n`]})]})}function R(n={}){let{wrapper:t}=n.components||{};return t?(0,e.jsx)(t,Object.assign({},n,{children:(0,e.jsx)(h,n)})):h(n)}var j=R;return f(M);})();\n;return Component;"
}
\ No newline at end of file
diff --git a/apps/web/src/__generated__/questions/quiz/how-do-you-validate-form-elements-using-the-constraint-validation-api/locales/en-US.json b/apps/web/src/__generated__/questions/quiz/how-do-you-validate-form-elements-using-the-constraint-validation-api/locales/en-US.json
index f089e8c69..13d304e67 100644
--- a/apps/web/src/__generated__/questions/quiz/how-do-you-validate-form-elements-using-the-constraint-validation-api/locales/en-US.json
+++ b/apps/web/src/__generated__/questions/quiz/how-do-you-validate-form-elements-using-the-constraint-validation-api/locales/en-US.json
@@ -5,5 +5,5 @@
"title": "How do you validate form elements using the Constraint Validation API?",
"gitHubEditUrl": "https://github.com/yangshun/top-javascript-interview-questions/blob/main/questions/how-do-you-validate-form-elements-using-the-constraint-validation-api/en-US.mdx"
},
- "solution": "var Component=(()=>{var h=Object.create;var o=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var g=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),v=(i,e)=>{for(var t in e)o(i,t,{get:e[t],enumerable:!0})},d=(i,e,t,a)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let l of m(e))!y.call(i,l)&&l!==t&&o(i,l,{get:()=>e[l],enumerable:!(a=u(e,l))||a.enumerable});return i};var f=(i,e,t)=>(t=i!=null?h(p(i)):{},d(e||!i||!i.__esModule?o(t,\"default\",{value:i,enumerable:!0}):t,i)),V=i=>d(o({},\"__esModule\",{value:!0}),i);var r=g((I,s)=>{s.exports=_jsx_runtime});var w={};v(w,{default:()=>k,frontmatter:()=>b});var n=f(r()),b={title:\"How do you validate form elements using the Constraint Validation API?\"};function c(i){let e=Object.assign({h2:\"h2\",p:\"p\",code:\"code\",pre:\"pre\",hr:\"hr\",h3:\"h3\",h4:\"h4\",ul:\"ul\",li:\"li\",a:\"a\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.h2,{children:\"TL;DR\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"The Constraint Validation API provides a way to validate form elements in HTML. You can use properties like \",(0,n.jsx)(e.code,{children:\"validity\"}),\", \",(0,n.jsx)(e.code,{children:\"validationMessage\"}),\", and methods like \",(0,n.jsx)(e.code,{children:\"checkValidity()\"}),\" and \",(0,n.jsx)(e.code,{children:\"setCustomValidity()\"}),\". For example, to check if an input is valid, you can use:\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const input = document.querySelector('input');\nif (input.checkValidity()) {\n console.log('Input is valid');\n} else {\n console.log(input.validationMessage);\n}\n`})}),`\n`,(0,n.jsx)(e.hr,{}),`\n`,(0,n.jsx)(e.h2,{children:\"How do you validate form elements using the Constraint Validation API?\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Introduction\"}),`\n`,(0,n.jsx)(e.p,{children:\"The Constraint Validation API is a set of methods and properties available on form elements that allow you to perform validation checks and provide feedback to users. This API is built into HTML5 and provides a way to validate form inputs without needing to write custom JavaScript validation logic.\"}),`\n`,(0,n.jsx)(e.h3,{children:\"Key properties and methods\"}),`\n`,(0,n.jsx)(e.h4,{children:(0,n.jsx)(e.code,{children:\"checkValidity()\"})}),`\n`,(0,n.jsxs)(e.p,{children:[\"The \",(0,n.jsx)(e.code,{children:\"checkValidity()\"}),\" method checks if an element meets all its validation constraints. It returns \",(0,n.jsx)(e.code,{children:\"true\"}),\" if the element is valid and \",(0,n.jsx)(e.code,{children:\"false\"}),\" otherwise.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const input = document.querySelector('input');\nif (input.checkValidity()) {\n console.log('Input is valid');\n} else {\n console.log('Input is invalid');\n}\n`})}),`\n`,(0,n.jsx)(e.h4,{children:(0,n.jsx)(e.code,{children:\"reportValidity()\"})}),`\n`,(0,n.jsxs)(e.p,{children:[\"The \",(0,n.jsx)(e.code,{children:\"reportValidity()\"}),\" method works like \",(0,n.jsx)(e.code,{children:\"checkValidity()\"}),\" but also displays the browser's default validation message if the element is invalid.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const input = document.querySelector('input');\nif (!input.reportValidity()) {\n console.log('Input is invalid');\n}\n`})}),`\n`,(0,n.jsx)(e.h4,{children:(0,n.jsx)(e.code,{children:\"setCustomValidity()\"})}),`\n`,(0,n.jsxs)(e.p,{children:[\"The \",(0,n.jsx)(e.code,{children:\"setCustomValidity()\"}),\" method allows you to set a custom validation message. If a custom message is set, the element will be considered invalid.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const input = document.querySelector('input');\ninput.setCustomValidity('This field is required');\nif (!input.checkValidity()) {\n console.log(input.validationMessage); // Outputs: This field is required\n}\n`})}),`\n`,(0,n.jsx)(e.h4,{children:(0,n.jsx)(e.code,{children:\"validity\"})}),`\n`,(0,n.jsxs)(e.p,{children:[\"The \",(0,n.jsx)(e.code,{children:\"validity\"}),\" property is an object that contains several boolean properties indicating the validity state of the element, such as \",(0,n.jsx)(e.code,{children:\"valid\"}),\", \",(0,n.jsx)(e.code,{children:\"valueMissing\"}),\", \",(0,n.jsx)(e.code,{children:\"typeMismatch\"}),\", etc.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const input = document.querySelector('input');\nif (input.validity.valueMissing) {\n console.log('Value is missing');\n}\n`})}),`\n`,(0,n.jsx)(e.h4,{children:(0,n.jsx)(e.code,{children:\"validationMessage\"})}),`\n`,(0,n.jsxs)(e.p,{children:[\"The \",(0,n.jsx)(e.code,{children:\"validationMessage\"}),\" property returns the message that will be shown to the user if the element is invalid.\"]}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-js\",children:`const input = document.querySelector('input');\nif (!input.checkValidity()) {\n console.log(input.validationMessage);\n}\n`})}),`\n`,(0,n.jsx)(e.h3,{children:\"Example\"}),`\n`,(0,n.jsx)(e.p,{children:\"Here is a complete example that demonstrates how to use the Constraint Validation API to validate a form:\"}),`\n`,(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:\"language-html\",children:`\n\n