{"id":319451,"date":"2021-03-12T09:01:02","date_gmt":"2021-03-12T09:01:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=319451"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=319451","title":{"rendered":"React: \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044b \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/98\/k9\/is\/98k9issmcul9hqqfqbjuflx57uo.png\"><\/p>\n<p>  \u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a, \u0434\u0440\u0443\u0437\u044c\u044f!<\/p>\n<p>  \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447. \u0427\u0442\u043e \u0432 \u043d\u0435\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u00ab\u0442\u0443\u0434\u0443\u0448\u043a\u0443\u00bb \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432 React-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445: useState, useContext + useReducer, Redux Toolkit \u0438 Recoil.<\/p>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u0432\u0430\u0436\u0435\u043d \u0432\u044b\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c.<\/p>\n<p>  \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0438\u043c\u0435\u044e\u0449\u0435\u0439 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e. \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0442\u043e\u0442 \u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447 \u0438\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u0430\u043a \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0432\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u043b\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  \u0423\u0441\u043b\u043e\u0432\u043d\u043e, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435. \u041f\u043e\u0434 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c, \u043e\u0431\u044b\u0447\u043d\u043e, \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0438\u043b\u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c, \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044f \u043f\u043e\u0434 \u044d\u0442\u0438\u043c \u0442\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043e\u0434\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c. \u0423\u0441\u043b\u043e\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0438 \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e useState(), \u043c\u043e\u0436\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u043f\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c), \u0430 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 Redux, \u0433\u0434\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043e\u0431\u044b\u0447\u043d\u043e, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0440\u0435\u0437 (slice) \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 UI, \u0442\u043e\u0447\u043d\u0435\u0435, \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e).<br \/>  <a name=\"habracut\"><\/a><br \/>  \u0412\u0430\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u0430 \u0442\u0435\u043c\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442 \u043f\u0440\u0438 \u043d\u0435\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c\u043e\u0439 \u0432 \u043d\u0435\u043c \u043b\u043e\u0433\u0438\u043a\u0438. \u041c\u044b \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>  \u042f \u043d\u0435 \u0431\u0443\u0434\u0443 \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0431\u043e\u0442\u044b \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430, \u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0443\u0441\u044c \u043e\u0431\u0449\u0438\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435\u043c \u0438 \u0441\u0441\u044b\u043b\u043a\u0430\u043c\u0438 \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u044b. \u0414\u043b\u044f \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f UI \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/react-bootstrap.github.io\/\" rel=\"nofollow noopener noreferrer\">react-bootstrap<\/a>.<\/p>\n<p>  <a href=\"https:\/\/github.com\/harryheman\/React-Projects\/tree\/main\/client\/state-management\" rel=\"nofollow noopener noreferrer\">\u041a\u043e\u0434 \u043d\u0430 GitHub<\/a><br \/>  <a href=\"https:\/\/codesandbox.io\/s\/react-state-management-ng9l1\" rel=\"nofollow noopener noreferrer\">\u041f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430 \u043d\u0430 CodeSandbox<\/a><\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Create React App:<\/p>\n<pre><code class=\"bash\">yarn create react-app state-management # \u0438\u043b\u0438 npm init react-app state-management # \u0438\u043b\u0438 npx create-react-app state-management <\/code><\/pre>\n<p>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"bash\">yarn add bootstrap react-bootstrap nanoid # \u0438\u043b\u0438 npm i bootstrap react-bootstrap nanoid <\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>bootstrap, react-bootstrap \u2014 \u0441\u0442\u0438\u043b\u0438<\/li>\n<li><a href=\"https:\/\/www.npmjs.com\/package\/nanoid\" rel=\"nofollow noopener noreferrer\">nanoid<\/a> \u2014 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e ID<\/li>\n<\/ul>\n<p>  \u0412 src \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u00abuse-state\u00bb \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0442\u0443\u0434\u0443\u0448\u043a\u0438.<\/p>\n<h3>useState()<\/h3>\n<p>  <a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/md\/hooks.md\" rel=\"nofollow noopener noreferrer\">\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e \u0445\u0443\u043a\u0430\u043c<\/a><\/p>\n<p>  \u0425\u0443\u043a \u00abuseState()\u00bb \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0441 \u0434\u0432\u0443\u043c\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438: \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u043e\u043c \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0445\u0443\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">const [state, setState] = useState(initialValue) <\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>state \u2014 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/li>\n<li>setState \u2014 \u0441\u0435\u0442\u0442\u0435\u0440<\/li>\n<li>initialValue \u2014 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0438\u043b\u0438 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/li>\n<\/ul>\n<p>  \u041e\u0434\u043d\u0438\u043c \u0438\u0437 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0430\u0441\u0441\u0438\u0432\u0430, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445. \u041f\u043e \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044e, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0441\u0435\u0442\u0442\u0435\u0440\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c\u0441\u044f \u0441 \u00abset\u00bb + \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 \u0441 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0431\u0443\u043a\u0432\u044b ([count, setCount], [text, setText] \u0438 \u0442.\u043f.).<\/p>\n<p>  \u041f\u043e\u043a\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u043c\u0441\u044f \u0447\u0435\u0442\u044b\u0440\u044c\u043c\u044f \u0431\u0430\u0437\u043e\u0432\u044b\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f\u043c\u0438: \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 (\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435), \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u0438\u043c \u0441\u0435\u0431\u0435 \u0436\u0438\u0437\u043d\u044c \u0442\u0435\u043c, \u0447\u0442\u043e \u043d\u0430\u0448\u0435 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0444\u043e\u0440\u043c\u0443 \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043f\u0440\u0430\u043a\u0442\u0438\u043a\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0438).<\/p>\n<p>  \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"plaintext\">|--use-state   |--components     |--index.js     |--TodoForm.js     |--TodoList.js     |--TodoListItem.js   |--App.js <\/code><\/pre>\n<p>  \u0414\u0443\u043c\u0430\u044e, \u0442\u0443\u0442 \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<p>  \u0412 App.js \u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e useState() \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0438 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0438\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0441\u0435\u0442\u0442\u0435\u0440 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u043f\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0445\u0443\u043a import { useState } from 'react' \/\/ \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b import { TodoForm, TodoList } from '.\/components' \/\/ \u0441\u0442\u0438\u043b\u0438 import { Container } from 'react-bootstrap'  \/\/ \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \/\/ \u0438\u0437\u0443\u0447\u0438\u0442\u0435 \u0435\u0433\u043e \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f const initialState = {   todos: {     ids: ['1', '2', '3', '4'],     entities: {       1: {         id: '1',         text: 'Eat',         completed: true       },       2: {         id: '2',         text: 'Code',         completed: true       },       3: {         id: '3',         text: 'Sleep',         completed: false       },       4: {         id: '4',         text: 'Repeat',         completed: false       }     }   } }  export default function App() {   const [state, setState] = useState(initialState)    const { length } = state.todos.ids    return (     &lt;Container style={{ maxWidth: '480px' }} className='text-center'&gt;       &lt;h1 className='mt-2'&gt;useState&lt;\/h1&gt;       &lt;TodoForm setState={setState} \/&gt;       {length ? &lt;TodoList state={state} setState={setState} \/&gt; : null}     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  \u0412 TodoForm.js \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0445\u0443\u043a import { useState } from 'react' \/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 ID import { nanoid } from 'nanoid' \/\/ \u0441\u0442\u0438\u043b\u0438 import { Container, Form, Button } from 'react-bootstrap'  \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0435\u0442\u0442\u0435\u0440 export const TodoForm = ({ setState }) =&gt; {   const [text, setText] = useState('')    const updateText = ({ target: { value } }) =&gt; {     setText(value)   }    const addTodo = (e) =&gt; {     e.preventDefault()      const trimmed = text.trim()      if (trimmed) {       const id = nanoid(5)        const newTodo = { id, text, completed: false }        \/\/ \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435       setState((state) =&gt; ({         ...state,         todos: {           ...state.todos,           ids: state.todos.ids.concat(id),           entities: {             ...state.todos.entities,             [id]: newTodo           }         }       }))        setText('')     }   }    return (     &lt;Container className='mt-4'&gt;       &lt;h4&gt;Form&lt;\/h4&gt;       &lt;Form className='d-flex' onSubmit={addTodo}&gt;         &lt;Form.Control           type='text'           placeholder='Enter text...'           value={text}           onChange={updateText}         \/&gt;         &lt;Button variant='primary' type='submit'&gt;           Add         &lt;\/Button&gt;       &lt;\/Form&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  \u0412 TodoList.js \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043c \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">\/\/ \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 import { TodoListItem } from '.\/TodoListItem' \/\/ \u0441\u0442\u0438\u043b\u0438 import { Container, ListGroup } from 'react-bootstrap'  \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0441\u0435\u0442\u0442\u0435\u0440 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \/\/ \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u0442\u043e\u043c\u043a\u0430\u043c \/\/ \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443 export const TodoList = ({ state, setState }) =&gt; (   &lt;Container className='mt-2'&gt;     &lt;h4&gt;List&lt;\/h4&gt;     &lt;ListGroup&gt;       {state.todos.ids.map((id) =&gt; (         &lt;TodoListItem           key={id}           todo={state.todos.entities[id]}           setState={setState}         \/&gt;       ))}     &lt;\/ListGroup&gt;   &lt;\/Container&gt; ) <\/code><\/pre>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432 TodoListItem.js \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441\u0430\u043c\u043e\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u2014 \u0437\u0434\u0435\u0441\u044c \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438: \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0441\u0442\u0438\u043b\u0438 import { ListGroup, Form, Button } from 'react-bootstrap'  \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0437\u0430\u0434\u0430\u0447\u0443 \u0438 \u0441\u0435\u0442\u0442\u0435\u0440 export const TodoListItem = ({ todo, setState }) =&gt; {   const { id, text, completed } = todo    \/\/ \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438   const toggleTodo = () =&gt; {     setState((state) =&gt; {       \/\/ \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0430\u044f \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f       const { todos } = state        return {         ...state,         todos: {           ...todos,           entities: {             ...todos.entities,             [id]: {               ...todos.entities[id],               completed: !todos.entities[id].completed             }           }         }       }     })   }    \/\/ \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438   const updateTodo = ({ target: { value } }) =&gt; {     const trimmed = value.trim()      if (trimmed) {       setState((state) =&gt; {         const { todos } = state          return {           ...state,           todos: {             ...todos,             entities: {               ...todos.entities,               [id]: {                 ...todos.entities[id],                 text: trimmed               }             }           }         }       })     }   }    \/\/ \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438   const deleteTodo = () =&gt; {     setState((state) =&gt; {       const { todos } = state        const newIds = todos.ids.filter((_id) =&gt; _id !== id)        const newTodos = newIds.reduce((obj, id) =&gt; {         if (todos.entities[id]) return { ...obj, [id]: todos.entities[id] }         else return obj       }, {})        return {         ...state,         todos: {           ...todos,           ids: newIds,           entities: newTodos         }       }     })   }    \/\/ \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0444\u0438\u043d\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438   const inputStyles = {     outline: 'none',     border: 'none',     background: 'none',     textAlign: 'center',     textDecoration: completed ? 'line-through' : '',     opacity: completed ? '0.8' : '1'   }    return (     &lt;ListGroup.Item className='d-flex align-items-baseline'&gt;       &lt;Form.Check         type='checkbox'         checked={completed}         onChange={toggleTodo}       \/&gt;       &lt;Form.Control         style={inputStyles}         defaultValue={text}         onChange={updateTodo}         disabled={completed}       \/&gt;       &lt;Button variant='danger' onClick={deleteTodo}&gt;         Delete       &lt;\/Button&gt;     &lt;\/ListGroup.Item&gt;   ) } <\/code><\/pre>\n<p>  \u0412 components\/index.js \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u0439 \u044d\u043a\u0441\u043f\u043e\u0440\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432:<\/p>\n<pre><code class=\"javascript\">export { TodoForm } from '.\/TodoForm' export { TodoList } from '.\/TodoList' <\/code><\/pre>\n<p>  \u0424\u0430\u0439\u043b \u00abscr\/index.js\u00bb \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">import React from 'react' import { render } from 'react-dom'  \/\/ \u0441\u0442\u0438\u043b\u0438 import 'bootstrap\/dist\/css\/bootstrap.min.css'  \/\/ \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 import App from '.\/use-state\/App'  const root$ = document.getElementById('root') render(&lt;App \/&gt;, root$) <\/code><\/pre>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c:<\/p>\n<ul>\n<li>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\/\u0438\u043b\u0438 \u0441\u0435\u0442\u0442\u0435\u0440\u0430 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043e\u0431\u0443\u0441\u043b\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/li>\n<li>\u041b\u043e\u0433\u0438\u043a\u0430 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u0431\u0440\u043e\u0441\u0430\u043d\u0430 \u043f\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c \u0438 \u0441\u043c\u0435\u0448\u0430\u043d\u0430 \u0441 \u043b\u043e\u0433\u0438\u043a\u043e\u0439 \u0441\u0430\u043c\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/li>\n<li>\u0421\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0432\u044b\u0442\u0435\u043a\u0430\u044e\u0449\u0430\u044f \u0438\u0437 \u0435\u0433\u043e \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438<\/li>\n<li>\u041e\u0434\u043d\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438, \u043d\u0430\u0445\u043e\u0434\u044f\u0449\u0438\u043c\u0438\u0441\u044f \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438, \u043d\u043e \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0434\u0434\u0435\u0440\u0435\u0432\u044c\u044f\u0445 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e DOM   <\/li>\n<\/ul>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 useContext()\/ useReducer().<\/p>\n<h3>useContext() + useReducer()<\/h3>\n<p>  <a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/md\/hooks.md\" rel=\"nofollow noopener noreferrer\">\u0428\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e \u0445\u0443\u043a\u0430\u043c<\/a><\/p>\n<p>  \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 (context) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043c\u0438\u043d\u0443\u044f \u0438\u0445 \u043f\u0440\u0435\u0434\u043a\u043e\u0432. \u0425\u0443\u043a \u00abuseContext()\u00bb \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u043b\u044e\u0431\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435, \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u043e\u043c \u0432 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 (provider).<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430:<\/p>\n<pre><code class=\"javascript\">const TodoContext = createContext() <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c:<\/p>\n<pre><code class=\"javascript\">&lt;TodoContext.Provider value={state}&gt;   &lt;App \/&gt; &lt;\/TodoContext.Provider&gt; <\/code><\/pre>\n<p>  \u0418\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u043d\u0438\u044f \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435:<\/p>\n<pre><code class=\"javascript\">const state = useContext(TodoContext) <\/code><\/pre>\n<p>  \u0425\u0443\u043a \u00abuseReducer()\u00bb \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 (reducer) \u0438 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435. \u041e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 (dispatch) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (actions), \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0421\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0445\u0443\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">const [state, dispatch] = useReducer(todoReducer, initialState) <\/code><\/pre>\n<p>  \u0410\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a: \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u0432 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440, \u0430 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0438\u043f\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (action.type) \u0438 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (action.payload) \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<p>  \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u0438 useContext() \u0438 useReducer() \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0445 useReducer(), \u043b\u044e\u0431\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0443, \u044f\u0432\u043b\u044f\u044e\u0449\u0435\u043c\u0443\u0441\u044f \u043f\u043e\u0442\u043e\u043c\u043a\u043e\u043c \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u00abuse-reducer\u00bb \u0434\u043b\u044f \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0442\u0443\u0434\u0443\u0448\u043a\u0438. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"plaintext\">|--use-reducer   |--modules     |--components       |--index.js       |--TodoForm.js       |--TodoList.js       |--TodoListItem.js     |--todoReducer       |--actions.js       |--actionTypes.js       |--todoReducer.js     |--todoContext.js   |--App.js <\/code><\/pre>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u0430. \u0412 actionTypes.js \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0442\u0438\u043f\u044b (\u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439:<\/p>\n<pre><code class=\"javascript\">const ADD_TODO = 'ADD_TODO' const TOGGLE_TODO = 'TOGGLE_TODO' const UPDATE_TODO = 'UPDATE_TODO' const DELETE_TODO = 'DELETE_TODO'  export { ADD_TODO, TOGGLE_TODO, UPDATE_TODO, DELETE_TODO } <\/code><\/pre>\n<p>  \u0422\u0438\u043f\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0442\u0430\u043a \u0438 \u043f\u0440\u0438 \u0432\u044b\u0431\u043e\u0440\u0435 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u0430 \u0441\u043b\u0443\u0447\u0430\u044f (case reducer) \u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u00abswitch\u00bb. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434, \u043a\u043e\u0433\u0434\u0430 \u0442\u0438\u043f\u044b, \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0438 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u0422\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u0435\u0442\u0441\u044f \u00ab\u0443\u0442\u0438\u043d\u043e\u0439\u00bb \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>  \u0412 actions.js \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 (action creators), \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u0444\u043e\u0440\u043c\u044b (\u0434\u043b\u044f \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u0430):<\/p>\n<pre><code class=\"javascript\">import { ADD_TODO, TOGGLE_TODO, UPDATE_TODO, DELETE_TODO } from '.\/actionTypes'  const createAction = (type, payload) =&gt; ({ type, payload })  const addTodo = (newTodo) =&gt; createAction(ADD_TODO, newTodo) const toggleTodo = (todoId) =&gt; createAction(TOGGLE_TODO, todoId) const updateTodo = (payload) =&gt; createAction(UPDATE_TODO, payload) const deleteTodo = (todoId) =&gt; createAction(DELETE_TODO, todoId)  export { addTodo, toggleTodo, updateTodo, deleteTodo } <\/code><\/pre>\n<p>  \u0412 todoReducer.js \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0430\u043c \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440. \u0415\u0449\u0435 \u0440\u0430\u0437: \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e, \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0438 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0438\u043f\u0430 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 (\u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438) \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u043f\u0440\u0438\u0432\u043e\u0434\u044f\u0449\u0438\u0435 \u043a \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a\u0436\u0435, \u043a\u0430\u043a \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0442\u0443\u0434\u0443\u0448\u043a\u0438, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e setState() \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435.<\/p>\n<pre><code class=\"javascript\">\/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 ID import { nanoid } from 'nanoid' \/\/ \u0442\u0438\u043f\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 import * as actions from '.\/actionTypes'  export const todoReducer = (state, action) =&gt; {   const { todos } = state    switch (action.type) {     case actions.ADD_TODO: {       const { payload: newTodo } = action        const id = nanoid(5)        return {         ...state,         todos: {           ...todos,           ids: todos.ids.concat(id),           entities: {             ...todos.entities,             [id]: { id, ...newTodo }           }         }       }     }      case actions.TOGGLE_TODO: {       const { payload: id } = action        return {         ...state,         todos: {           ...todos,           entities: {             ...todos.entities,             [id]: {               ...todos.entities[id],               completed: !todos.entities[id].completed             }           }         }       }     }      case actions.UPDATE_TODO: {       const { payload: id, text } = action        return {         ...state,         todos: {           ...todos,           entities: {             ...todos.entities,             [id]: {               ...todos.entities[id],               text             }           }         }       }     }      case actions.DELETE_TODO: {       const { payload: id } = action        const newIds = todos.ids.filter((_id) =&gt; _id !== id)        const newTodos = newIds.reduce((obj, id) =&gt; {         if (todos.entities[id]) return { ...obj, [id]: todos.entities[id] }         else return obj       }, {})        return {         ...state,         todos: {           ...todos,           ids: newIds,           entities: newTodos         }       }     }     \/\/ \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e (\u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 case) \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432 \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u043d\u043e\u043c \u0432\u0438\u0434\u0435     default:       return state   } } <\/code><\/pre>\n<p>  \u0412 todoContext.js \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u043e\u043c \u0438\u0437 useReducer():<\/p>\n<pre><code class=\"javascript\">\/\/ react import { createContext, useReducer, useContext } from 'react' \/\/ \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 import { todoReducer } from '.\/todoReducer\/todoReducer'  \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 const TodoContext = createContext()  \/\/ \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 const initialState = {   todos: {     ids: ['1', '2', '3', '4'],     entities: {       1: {         id: '1',         text: 'Eat',         completed: true       },       2: {         id: '2',         text: 'Code',         completed: true       },       3: {         id: '3',         text: 'Sleep',         completed: false       },       4: {         id: '4',         text: 'Repeat',         completed: false       }     }   } }  \/\/ \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 export const TodoProvider = ({ children }) =&gt; {   const [state, dispatch] = useReducer(todoReducer, initialState)    return (     &lt;TodoContext.Provider value={{ state, dispatch }}&gt;       {children}     &lt;\/TodoContext.Provider&gt;   ) }  \/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 export const useTodoContext = () =&gt; useContext(TodoContext) <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 src\/index.js \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">\/\/ React, ReactDOM \u0438 \u0441\u0442\u0438\u043b\u0438  import { TodoProvider } from '.\/use-reducer\/modules\/TodoContext'  import App from '.\/use-reducer\/App'  const root$ = document.getElementById('root') render(   &lt;TodoProvider&gt;     &lt;App \/&gt;   &lt;\/TodoProvider&gt;,   root$ ) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432. \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e useTodoContext(), \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"javascript\">import { useTodoContext } from '..\/TodoContext'  \/\/ \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 const { state, dispatch } = useTodoContext() <\/code><\/pre>\n<p>  \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e dispatch(), \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430:<\/p>\n<pre><code class=\"javascript\">import * as actions from '..\/todoReducer\/actions'  \/\/ \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 dispatch(actions.addTodo(newTodo)) <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041a\u043e\u0434 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/b>                         <\/p>\n<div class=\"spoiler_text\">App.js:<\/p>\n<pre><code class=\"javascript\">\/\/ components import { TodoForm, TodoList } from '.\/modules\/components' \/\/ styles import { Container } from 'react-bootstrap' \/\/ context import { useTodoContext } from '.\/modules\/TodoContext'  export default function App() {   const { state } = useTodoContext()    const { length } = state.todos.ids    return (     &lt;Container style={{ maxWidth: '480px' }} className='text-center'&gt;       &lt;h1 className='mt-2'&gt;useReducer&lt;\/h1&gt;       &lt;TodoForm \/&gt;       {length ? &lt;TodoList \/&gt; : null}     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoForm.js:<\/p>\n<pre><code class=\"javascript\">\/\/ react import { useState } from 'react' \/\/ styles import { Container, Form, Button } from 'react-bootstrap' \/\/ context import { useTodoContext } from '..\/TodoContext' \/\/ actions import * as actions from '..\/todoReducer\/actions'  export const TodoForm = () =&gt; {   const { dispatch } = useTodoContext()   const [text, setText] = useState('')    const updateText = ({ target: { value } }) =&gt; {     setText(value)   }    const handleAddTodo = (e) =&gt; {     e.preventDefault()      const trimmed = text.trim()      if (trimmed) {       const newTodo = { text, completed: false }        dispatch(actions.addTodo(newTodo))        setText('')     }   }    return (     &lt;Container className='mt-4'&gt;       &lt;h4&gt;Form&lt;\/h4&gt;       &lt;Form className='d-flex' onSubmit={handleAddTodo}&gt;         &lt;Form.Control           type='text'           placeholder='Enter text...'           value={text}           onChange={updateText}         \/&gt;         &lt;Button variant='primary' type='submit'&gt;           Add         &lt;\/Button&gt;       &lt;\/Form&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoList.js:<\/p>\n<pre><code class=\"javascript\">\/\/ components import { TodoListItem } from '.\/TodoListItem' \/\/ styles import { Container, ListGroup } from 'react-bootstrap' \/\/ context import { useTodoContext } from '..\/TodoContext'  export const TodoList = () =&gt; {   const {     state: { todos }   } = useTodoContext()    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;List&lt;\/h4&gt;       &lt;ListGroup&gt;         {todos.ids.map((id) =&gt; (           &lt;TodoListItem key={id} todo={todos.entities[id]} \/&gt;         ))}       &lt;\/ListGroup&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoListItem.js:<\/p>\n<pre><code class=\"javascript\">\/\/ styles import { ListGroup, Form, Button } from 'react-bootstrap' \/\/ context import { useTodoContext } from '..\/TodoContext' \/\/ actions import * as actions from '..\/todoReducer\/actions'  export const TodoListItem = ({ todo }) =&gt; {   const { dispatch } = useTodoContext()    const { id, text, completed } = todo    const handleUpdateTodo = ({ target: { value } }) =&gt; {     const trimmed = value.trim()      if (trimmed) {       dispatch(actions.updateTodo({ id, trimmed }))     }   }    const inputStyles = {     outline: 'none',     border: 'none',     background: 'none',     textAlign: 'center',     textDecoration: completed ? 'line-through' : '',     opacity: completed ? '0.8' : '1'   }    return (     &lt;ListGroup.Item className='d-flex align-items-baseline'&gt;       &lt;Form.Check         type='checkbox'         checked={completed}         onChange={() =&gt; dispatch(actions.toggleTodo(id))}       \/&gt;       &lt;Form.Control         style={inputStyles}         defaultValue={text}         onChange={handleUpdateTodo}         disabled={completed}       \/&gt;       &lt;Button variant='danger' onClick={() =&gt; dispatch(actions.deleteTodo(id))}&gt;         Delete       &lt;\/Button&gt;     &lt;\/ListGroup.Item&gt;   ) } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 \u0434\u0432\u0435 \u043f\u0435\u0440\u0432\u044b\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c useState() \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c. \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0432 \u043a \u043f\u043e\u043c\u043e\u0449\u0438 \u043e\u0434\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0448\u0438\u0442\u044c \u0438 \u0442\u0440\u0435\u0442\u044c\u044e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u2014 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. <a href=\"https:\/\/immerjs.github.io\/immer\/docs\/introduction\" rel=\"nofollow noopener noreferrer\">immer<\/a> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u043c\u0443\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f (\u0434\u0430, \u044f \u0437\u043d\u0430\u044e, \u043a\u0430\u043a \u044d\u0442\u043e \u0437\u0432\u0443\u0447\u0438\u0442), \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u00abproduce()\u00bb. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b \u00abtodoReducer\/todoProducer.js\u00bb:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u0430\u044f immer import produce from 'immer' import { nanoid } from 'nanoid' \/\/ \u0442\u0438\u043f\u044b \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 import * as actions from '.\/actionTypes'  \/\/ \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435 \u0441 &quot;\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439&quot; \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u0430 \/\/ \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f draft - \u0447\u0435\u0440\u043d\u043e\u0432\u0438\u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f export const todoProducer = produce((draft, action) =&gt; {   const {     todos: { ids, entities }   } = draft    switch (action.type) {     case actions.ADD_TODO: {       const { payload: newTodo } = action        const id = nanoid(5)        ids.push(id)       entities[id] = { id, ...newTodo }       break     }     case actions.TOGGLE_TODO: {       const { payload: id } = action        entities[id].completed = !entities[id].completed       break     }     case actions.UPDATE_TODO: {       const { payload: id, text } = action        entities[id].text = text       break     }     case actions.DELETE_TODO: {       const { payload: id } = action        ids.splice(ids.indexOf(id), 1)       delete entities[id]       break     }     default:       return draft   } }) <\/code><\/pre>\n<p>  \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u043d\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u043c\u043e\u0435 immer, \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043b\u0438\u0431\u043e \u043c\u0443\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e, \u043b\u0438\u0431\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e. \u041d\u0435\u043b\u044c\u0437\u044f \u0434\u0435\u043b\u0430\u0442\u044c \u0438 \u0442\u043e, \u0438 \u0434\u0440\u0443\u0433\u043e\u0435 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e.<\/p>\n<p>  \u0412\u043d\u043e\u0441\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 todoContext.js:<\/p>\n<pre><code class=\"javascript\">\/\/ import { todoReducer } from '.\/todoReducer\/todoReducer' import { todoProducer } from '.\/todoReducer\/todoProducer'  \/\/ \u0432 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0435 \/\/ const [state, dispatch] = useReducer(todoReducer, initialState) const [state, dispatch] = useReducer(todoProducer, initialState) <\/code><\/pre>\n<p>  \u0412\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u043a\u0430\u043a \u0438 \u043f\u0440\u0435\u0436\u0434\u0435, \u043d\u043e \u043a\u043e\u0434 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u0430 \u0441\u0442\u0430\u043b\u043e \u043b\u0435\u0433\u0447\u0435 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c.<\/p>\n<p>  \u0414\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<h3>Redux Toolkit<\/h3>\n<p>  <a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/md\/redux-toolkit.md\" rel=\"nofollow noopener noreferrer\">\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e Redux Toolkit<\/a><\/p>\n<p>  Redux Toolkit \u2014 \u044d\u0442\u043e \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0449\u0438\u0439 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 Redux. \u0421\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 Redux \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0445\u043e\u0436 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e useContext() + useReducer():<\/p>\n<ul>\n<li>\u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0434\u043d\u043e\u043c \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 (store)<\/li>\n<li>\u0414\u043e\u0447\u0435\u0440\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0432 Provider \u0438\u0437 <a href=\"https:\/\/react-redux.js.org\/\" rel=\"nofollow noopener noreferrer\">react-redux<\/a>, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u043f\u0430 \u00abstore\u00bb \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435<\/li>\n<li>\u0420\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u044b (reducers) \u043a\u0430\u0436\u0434\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e combineReducers() \u0432 \u043e\u0434\u0438\u043d \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 (root reducer), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0432 createStore()<\/li>\n<li>\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u044e\u0442\u0441\u044f \u043a \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0443 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e connect() (+ mapStateToProps(), mapDispatchToProps()) \u0438 \u0442.\u0434.<\/li>\n<\/ul>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c\u0438 \u0443\u0442\u0438\u043b\u0438\u0442\u0430\u043c\u0438 \u0438\u0437 Redux Toolkit:<\/p>\n<ul>\n<li>configureStore() \u2014 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430<\/li>\n<li>createSlice() \u2014 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0435\u0439 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f<\/li>\n<li>createEntityAdapter() \u2014 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439<\/li>\n<\/ul>\n<p>  \u0427\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435 \u043c\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u0434\u0430\u0447 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0443\u0442\u0438\u043b\u0438\u0442:<\/p>\n<ul>\n<li>createSelector() \u2014 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u0432<\/li>\n<li>createAsyncThunk() \u2014 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 (thunk)<\/li>\n<\/ul>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0445\u0443\u043a\u0438 \u0438\u0437 react-redux: \u00abuseDispatch()\u00bb \u2014 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0443 \u0438 \u00abuseSelector()\u00bb \u2014 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430\u043c.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u00abredux-toolkit\u00bb \u0434\u043b\u044f \u0442\u0440\u0435\u0442\u044c\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0442\u0443\u0434\u0443\u0448\u043a\u0438. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Redux Toolkit:<\/p>\n<pre><code class=\"bash\">yarn add @reduxjs\/toolkit # \u0438\u043b\u0438 npm i @reduxjs\/toolkit <\/code><\/pre>\n<p>  \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"plaintext\">|--redux-toolkit   |--modules     |--components       |--index.js       |--TodoForm.js       |--TodoList.js       |--TodoListItem.js   |--slices     |--todosSlice.js   |--App.js   |--store.js <\/code><\/pre>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430. store.js:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 import { configureStore } from '@reduxjs\/toolkit' \/\/ \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 import todosReducer from '.\/modules\/slices\/todosSlice'  \/\/ \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 const preloadedState = {   todos: {     ids: ['1', '2', '3', '4'],     entities: {       1: {         id: '1',         text: 'Eat',         completed: true       },       2: {         id: '2',         text: 'Code',         completed: true       },       3: {         id: '3',         text: 'Sleep',         completed: false       },       4: {         id: '4',         text: 'Repeat',         completed: false       }     }   } }  \/\/ \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 const store = configureStore({   reducer: {     todos: todosReducer   },   preloadedState })  export default store <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 src\/index.js \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">\/\/ React, ReactDOM &amp; \u0441\u0442\u0438\u043b\u0438  \/\/ \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 import { Provider } from 'react-redux'  \/\/ \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 import App from '.\/redux-toolkit\/App' \/\/ \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 import store from '.\/redux-toolkit\/store'  const root$ = document.getElementById('root') render(   &lt;Provider store={store}&gt;     &lt;App \/&gt;   &lt;\/Provider&gt;,   root$ ) <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u0443. slices\/todosSlice.js:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 import {   createSlice,   createEntityAdapter } from '@reduxjs\/toolkit'  \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440 const todosAdapter = createEntityAdapter()  \/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c { ids: [], entities: {} } const initialState = todosAdapter.getInitialState()  \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f const todosSlice = createSlice({   \/\/ \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u044e\u0447, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u0430 \u043f\u0440\u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438   name: 'todos',   \/\/ \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435   initialState,   \/\/ \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u044b   reducers: {     \/\/ \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e { type: 'todos\/addTodo', payload: newTodo }     addTodo: todosAdapter.addOne,     \/\/ Redux Toolkit \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 immer \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f     toggleTodo(state, action) {       const { payload: id } = action       const todo = state.entities[id]       todo.completed = !todo.completed     },     updateTodo(state, action) {       const { id, text } = action.payload       const todo = state.entities[id]       todo.text = text     },     deleteTodo: todosAdapter.removeOne   } })  \/\/ \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 entities \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 export const { selectAll: selectAllTodos } = todosAdapter.getSelectors(   (state) =&gt; state.todos )  \/\/ \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 export const {   addTodo,   toggleTodo,   updateTodo,   deleteTodo } = todosSlice.actions  \/\/ \u044d\u0441\u043a\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440 export default todosSlice.reducer <\/code><\/pre>\n<p>  \u0412 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f useDispatch(), \u0430 \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438, \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0438\u0437 todosSlice.js:<\/p>\n<pre><code class=\"javascript\">import { useDispatch } from 'react-redux' import { addTodo } from '..\/slices\/todosSlice'  \/\/ \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 const dispatch = useDispatch()  dispatch(addTodo(newTodo)) <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u043d\u0430\u0448\u0435\u0439 \u0442\u0443\u0434\u0443\u0448\u043a\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0437\u0430\u0434\u0430\u0447, \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447 \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443. \u0422\u0430\u043a\u0436\u0435 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u0434\u0430\u0447 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430.<\/p>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u00abfake API\u00bb \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/github.com\/typicode\/json-server\" rel=\"nofollow noopener noreferrer\">JSON Server<\/a>. \u0412\u043e\u0442 <a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/md\/json-server\/README.md\" rel=\"nofollow noopener noreferrer\">\u0448\u043f\u0430\u0440\u0433\u0430\u043b\u043a\u0430 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u0438\u043c<\/a>. \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c json-server \u0438 <a href=\"https:\/\/www.npmjs.com\/package\/concurrently\" rel=\"nofollow noopener noreferrer\">concurrently<\/a> \u2014 \u0443\u0442\u0438\u043b\u0438\u0442\u0443 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u0438 \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<pre><code class=\"javascript\">yarn add json-server concurrently # \u0438\u043b\u0438 npm i json-server concurrently <\/code><\/pre>\n<p>  \u0412\u043d\u043e\u0441\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u0437\u0434\u0435\u043b \u00abscripts\u00bb package.json:<\/p>\n<pre><code class=\"json\">&quot;server&quot;: &quot;concurrently \\&quot;json-server -w db.json -p 5000 -d 1000\\&quot; \\&quot;yarn start\\&quot;&quot; <\/code><\/pre>\n<p>  <\/p>\n<ul>\n<li>-w \u2014 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043d\u0430\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u0437\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u043c\u0438 \u0444\u0430\u0439\u043b\u0430 \u00abdb.json\u00bb<\/li>\n<li>-p \u2014 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043f\u043e\u0440\u0442, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u0440\u0442 3000<\/li>\n<li>-d \u2014 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/li>\n<\/ul>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b \u00abdb.json\u00bb \u0432 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 (state-management):<\/p>\n<pre><code class=\"json\">{   &quot;todos&quot;: [     {       &quot;id&quot;: &quot;1&quot;,       &quot;text&quot;: &quot;Eat&quot;,       &quot;completed&quot;: true,       &quot;visible&quot;: true     },     {       &quot;id&quot;: &quot;2&quot;,       &quot;text&quot;: &quot;Code&quot;,       &quot;completed&quot;: true,       &quot;visible&quot;: true     },     {       &quot;id&quot;: &quot;3&quot;,       &quot;text&quot;: &quot;Sleep&quot;,       &quot;completed&quot;: false,       &quot;visible&quot;: true     },     {       &quot;id&quot;: &quot;4&quot;,       &quot;text&quot;: &quot;Repeat&quot;,       &quot;completed&quot;: false,       &quot;visible&quot;: true     }   ] } <\/code><\/pre>\n<p>  \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u0441\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438\u0437 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u0440\u0442 3000 (\u043f\u043e\u0440\u0442, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0443\u0449\u0435\u043d \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438). \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u043b\u0438\u0441\u044c \u043d\u0430 \u043f\u043e\u0440\u0442 5000 (\u043f\u043e\u0440\u0442, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c json-server), \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0445 \u043f\u0440\u043e\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 package.json \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443:<\/p>\n<pre><code class=\"json\">&quot;proxy&quot;: &quot;http:\/\/localhost:5000&quot; <\/code><\/pre>\n<p>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u0435\u0440\u0432\u0435\u0440 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u00abyarn server\u00bb.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. slices\/filterSlice.js:<\/p>\n<pre><code class=\"javascript\">import { createSlice } from '@reduxjs\/toolkit'  \/\/ \u0444\u0438\u043b\u044c\u0442\u0440\u044b export const Filters = {   All: 'all',   Active: 'active',   Completed: 'completed' }  \/\/ \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 - \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 const initialState = {   status: Filters.All }  \/\/ \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0430 const filterSlice = createSlice({   name: 'filter',   initialState,   reducers: {     setFilter(state, action) {       state.status = action.payload     }   } })  export const { setFilter } = filterSlice.actions  export default filterSlice.reducer <\/code><\/pre>\n<p>  \u0412\u043d\u043e\u0441\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 store.js:<\/p>\n<pre><code class=\"javascript\">\/\/ \u043d\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f preloadedState import { configureStore } from '@reduxjs\/toolkit' import todosReducer from '.\/modules\/slices\/todosSlice' import filterReducer from '.\/modules\/slices\/filterSlice'  const store = configureStore({   reducer: {     todos: todosReducer,     filter: filterReducer   } })  export default store <\/code><\/pre>\n<p>  \u0412\u043d\u043e\u0441\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 todosSlice.js:<\/p>\n<pre><code class=\"javascript\">import {   createSlice,   createEntityAdapter,   \/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u0432   createSelector,   \/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439   createAsyncThunk } from '@reduxjs\/toolkit' \/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 import axios from 'axios'  \/\/ \u0444\u0438\u043b\u044c\u0442\u0440\u044b import { Filters } from '.\/filterSlice'  const todosAdapter = createEntityAdapter()  const initialState = todosAdapter.getInitialState({   \/\/ \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438   status: 'idle' })  \/\/ \u0430\u0434\u0440\u0435\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 const SERVER_URL = 'http:\/\/localhost:5000\/todos' \/\/ \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c export const fetchTodos = createAsyncThunk('todos\/fetchTodos', async () =&gt; {   try {     const response = await axios(SERVER_URL)     return response.data   } catch (err) {     console.error(err.toJSON())   } })  const todosSlice = createSlice({   name: 'todos',   initialState,   reducers: {     addTodo: todosAdapter.addOne,     toggleTodo(state, action) {       const { payload: id } = action       const todo = state.entities[id]       todo.completed = !todo.completed     },     updateTodo(state, action) {       const { id, text } = action.payload       const todo = state.entities[id]       todo.text = text     },     deleteTodo: todosAdapter.removeOne,     \/\/ \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447     completeAllTodos(state) {       Object.values(state.entities).forEach((todo) =&gt; {         todo.completed = true       })     },     \/\/ \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u044c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447     clearCompletedTodos(state) {       const completedIds = Object.values(state.entities)         .filter((todo) =&gt; todo.completed)         .map((todo) =&gt; todo.id)       todosAdapter.removeMany(state, completedIds)     }   },   \/\/ \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0440\u0435\u0434\u0443\u043a\u0442\u043e\u0440\u044b   extraReducers: (builder) =&gt; {     builder       \/\/ \u043f\u043e\u0441\u043b\u0435 \u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447       \/\/ \u043c\u0435\u043d\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430 \u043d\u0430 loading       \/\/ \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432 App.js       .addCase(fetchTodos.pending, (state) =&gt; {         state.status = 'loading'       })       \/\/ \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430       \/\/ \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u0445 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435       \/\/ \u0438 \u043c\u0435\u043d\u044f\u0435\u043c \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438       .addCase(fetchTodos.fulfilled, (state, action) =&gt; {         todosAdapter.setAll(state, action.payload)         state.status = 'idle'       })   } })  export const { selectAll: selectAllTodos } = todosAdapter.getSelectors(   (state) =&gt; state.todos )  \/\/ \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043e\u0442\u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 export const selectFilteredTodos = createSelector(   selectAllTodos,   (state) =&gt; state.filter,   (todos, filter) =&gt; {     const { status } = filter     if (status === Filters.All) return todos     return status === Filters.Active       ? todos.filter((todo) =&gt; !todo.completed)       : todos.filter((todo) =&gt; todo.completed)   } )  export const {   addTodo,   toggleTodo,   updateTodo,   deleteTodo,   completeAllTodos,   clearCompletedTodos } = todosSlice.actions  export default todosSlice.reducer <\/code><\/pre>\n<p>  \u0412\u043d\u043e\u0441\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 src\/index.js:<\/p>\n<pre><code class=\"javascript\">\/\/ \u043f\u043e\u0441\u043b\u0435 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 &quot;App&quot; import { fetchTodos } from '.\/redux-toolkit\/modules\/slices\/todosSlice'  store.dispatch(fetchTodos()) <\/code><\/pre>\n<p>  App.js \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0445\u0443\u043a \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u0430\u043c import { useSelector } from 'react-redux' \/\/ \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 - \u0441\u043f\u0438\u043d\u043d\u0435\u0440 import Loader from 'react-loader-spinner' \/\/ \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b import {   TodoForm,   TodoList,   TodoFilters,   TodoControls,   TodoStats } from '.\/modules\/components' \/\/ \u0441\u0442\u0438\u043b\u0438 import { Container } from 'react-bootstrap' \/\/ \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 entitites \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 import { selectAllTodos } from '.\/modules\/slices\/todosSlice'  export default function App() {   \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439   const { length } = useSelector(selectAllTodos)   \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u0443\u0441\u0430   const loadingStatus = useSelector((state) =&gt; state.todos.status)    \/\/ \u0441\u0442\u0438\u043b\u0438 \u0434\u043b\u044f \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438   const loaderStyles = {     position: 'absolute',     top: '50%',     left: '50%',     transform: 'translate(-50%, -50%)'   }    if (loadingStatus === 'loading')     return (       &lt;Loader         type='Oval'         color='#00bfff'         height={80}         width={80}         style={loaderStyles}       \/&gt;     )    return (     &lt;Container style={{ maxWidth: '480px' }} className='text-center'&gt;       &lt;h1 className='mt-2'&gt;Redux Toolkit&lt;\/h1&gt;       &lt;TodoForm \/&gt;       {length ? (         &lt;&gt;           &lt;TodoStats \/&gt;           &lt;TodoFilters \/&gt;           &lt;TodoList \/&gt;           &lt;TodoControls \/&gt;         &lt;\/&gt;       ) : null}     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041a\u043e\u0434 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/b>                         <\/p>\n<div class=\"spoiler_text\">TodoControls.js:<\/p>\n<pre><code class=\"javascript\">\/\/ redux import { useDispatch } from 'react-redux' \/\/ styles import { Container, ButtonGroup, Button } from 'react-bootstrap' \/\/ action creators import { completeAllTodos, clearCompletedTodos } from '..\/slices\/todosSlice'  export const TodoControls = () =&gt; {   const dispatch = useDispatch()    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;Controls&lt;\/h4&gt;       &lt;ButtonGroup&gt;         &lt;Button           variant='outline-secondary'           onClick={() =&gt; dispatch(completeAllTodos())}         &gt;           Complete all         &lt;\/Button&gt;         &lt;Button           variant='outline-secondary'           onClick={() =&gt; dispatch(clearCompletedTodos())}         &gt;           Clear completed         &lt;\/Button&gt;       &lt;\/ButtonGroup&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoFilters.js:<\/p>\n<pre><code class=\"javascript\">\/\/ redux import { useDispatch, useSelector } from 'react-redux' \/\/ styles import { Container, Form } from 'react-bootstrap' \/\/ filters &amp; action creator import { Filters, setFilter } from '..\/slices\/filterSlice'  export const TodoFilters = () =&gt; {   const dispatch = useDispatch()   const { status } = useSelector((state) =&gt; state.filter)    const changeFilter = (filter) =&gt; {     dispatch(setFilter(filter))   }    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;Filters&lt;\/h4&gt;       {Object.keys(Filters).map((key) =&gt; {         const value = Filters[key]         const checked = value === status          return (           &lt;Form.Check             key={value}             inline             label={value.toUpperCase()}             type='radio'             name='filter'             onChange={() =&gt; changeFilter(value)}             checked={checked}           \/&gt;         )       })}     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoForm.js:<\/p>\n<pre><code class=\"javascript\">\/\/ react import { useState } from 'react' \/\/ redux import { useDispatch } from 'react-redux' \/\/ libs import { nanoid } from 'nanoid' \/\/ styles import { Container, Form, Button } from 'react-bootstrap' \/\/ action creator import { addTodo } from '..\/slices\/todosSlice'  export const TodoForm = () =&gt; {   const dispatch = useDispatch()   const [text, setText] = useState('')    const updateText = ({ target: { value } }) =&gt; {     setText(value)   }    const handleAddTodo = (e) =&gt; {     e.preventDefault()      const trimmed = text.trim()      if (trimmed) {       const newTodo = { id: nanoid(5), text, completed: false }        dispatch(addTodo(newTodo))        setText('')     }   }    return (     &lt;Container className='mt-4'&gt;       &lt;h4&gt;Form&lt;\/h4&gt;       &lt;Form className='d-flex' onSubmit={handleAddTodo}&gt;         &lt;Form.Control           type='text'           placeholder='Enter text...'           value={text}           onChange={updateText}         \/&gt;         &lt;Button variant='primary' type='submit'&gt;           Add         &lt;\/Button&gt;       &lt;\/Form&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoList.js:<\/p>\n<pre><code class=\"javascript\">\/\/ redux import { useSelector } from 'react-redux' \/\/ component import { TodoListItem } from '.\/TodoListItem' \/\/ styles import { Container, ListGroup } from 'react-bootstrap' \/\/ selector import { selectFilteredTodos } from '..\/slices\/todosSlice'  export const TodoList = () =&gt; {   const filteredTodos = useSelector(selectFilteredTodos)    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;List&lt;\/h4&gt;       &lt;ListGroup&gt;         {filteredTodos.map((todo) =&gt; (           &lt;TodoListItem key={todo.id} todo={todo} \/&gt;         ))}       &lt;\/ListGroup&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoListItem.js:<\/p>\n<pre><code class=\"javascript\">\/\/ redux import { useDispatch } from 'react-redux' \/\/ styles import { ListGroup, Form, Button } from 'react-bootstrap' \/\/ action creators import { toggleTodo, updateTodo, deleteTodo } from '..\/slices\/todosSlice'  export const TodoListItem = ({ todo }) =&gt; {   const dispatch = useDispatch()    const { id, text, completed } = todo    const handleUpdateTodo = ({ target: { value } }) =&gt; {     const trimmed = value.trim()      if (trimmed) {       dispatch(updateTodo({ id, trimmed }))     }   }    const inputStyles = {     outline: 'none',     border: 'none',     background: 'none',     textAlign: 'center',     textDecoration: completed ? 'line-through' : '',     opacity: completed ? '0.8' : '1'   }    return (     &lt;ListGroup.Item className='d-flex align-items-baseline'&gt;       &lt;Form.Check         type='checkbox'         checked={completed}         onChange={() =&gt; dispatch(toggleTodo(id))}       \/&gt;       &lt;Form.Control         style={inputStyles}         defaultValue={text}         onChange={handleUpdateTodo}         disabled={completed}       \/&gt;       &lt;Button variant='danger' onClick={() =&gt; dispatch(deleteTodo(id))}&gt;         Delete       &lt;\/Button&gt;     &lt;\/ListGroup.Item&gt;   ) } <\/code><\/pre>\n<p>  TodoStats.js:<\/p>\n<pre><code class=\"javascript\">\/\/ react import { useState, useEffect } from 'react' \/\/ redux import { useSelector } from 'react-redux' \/\/ styles import { Container, ListGroup } from 'react-bootstrap' \/\/ selector import { selectAllTodos } from '..\/slices\/todosSlice'  export const TodoStats = () =&gt; {   const allTodos = useSelector(selectAllTodos)    const [stats, setStats] = useState({     total: 0,     active: 0,     completed: 0,     percent: 0   })    useEffect(() =&gt; {     if (allTodos.length) {       const total = allTodos.length       const completed = allTodos.filter((todo) =&gt; todo.completed).length       const active = total - completed       const percent = total === 0 ? 0 : Math.round((active \/ total) * 100) + '%'        setStats({         total,         active,         completed,         percent       })     }   }, [allTodos])    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;Stats&lt;\/h4&gt;       &lt;ListGroup horizontal&gt;         {Object.entries(stats).map(([[first, ...rest], count], index) =&gt; (           &lt;ListGroup.Item key={index}&gt;             {first.toUpperCase() + rest.join('')}: {count}           &lt;\/ListGroup.Item&gt;         ))}       &lt;\/ListGroup&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  \u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0438\u043c, \u0441 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435\u043c Redux Toolkit \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Redux \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u043b\u043e \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u043a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044e useContext() + useReducer() (\u043d\u0435\u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u043d\u043e \u0444\u0430\u043a\u0442), \u043d\u0435 \u0441\u0447\u0438\u0442\u0430\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e Redux \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0434\u043b\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u041e\u0434\u043d\u0430\u043a\u043e, Redux \u0432\u0441\u0435-\u0442\u0430\u043a\u0438 \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u0430\u043d \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u043a\u0430\u043a\u0430\u044f-\u0442\u043e \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438 \u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043a\u0440\u043e\u043c\u0435 useContext()\/useReducer(). \u041e\u0442\u0432\u0435\u0442: \u0434\u0430, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442. \u042d\u0442\u043e <a href=\"https:\/\/recoiljs.org\/\" rel=\"nofollow noopener noreferrer\">Recoil<\/a>.<\/p>\n<h3>Recoil<\/h3>\n<p>  <a href=\"https:\/\/github.com\/harryheman\/React-Total\/blob\/main\/md\/recoil.md\" rel=\"nofollow noopener noreferrer\">\u0420\u0443\u043a\u043e\u0432\u043e\u0434\u0441\u0442\u0432\u043e \u043f\u043e Recoil<\/a><\/p>\n<p>  Recoil \u2014 \u044d\u0442\u043e \u043d\u043e\u0432\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432 React-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. \u0427\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442 \u043d\u043e\u0432\u044b\u0439? \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0435\u0433\u043e API \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u043c\u043e\u0433\u0443\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c. \u041e\u0434\u043d\u0430\u043a\u043e, \u0442\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0442\u0443\u0434\u0443\u0448\u043a\u0438, \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c\u0438.<\/p>\n<p>  \u0412 \u043e\u0441\u043d\u043e\u0432\u0435 Recoil \u043b\u0435\u0436\u0430\u0442 \u0430\u0442\u043e\u043c\u044b \u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u044b. \u0410\u0442\u043e\u043c \u2014 \u044d\u0442\u043e \u0447\u0430\u0441\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u2014 \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f. \u0410\u0442\u043e\u043c\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u00abatom()\u00bb, \u0430 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u044b \u2014 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u00abselector()\u00bb. \u0414\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0437 \u0430\u0442\u043e\u043c\u043e\u0432 \u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0445\u0443\u043a\u0438 \u00abuseRecoilState()\u00bb (\u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438), \u00abuseRecoilValue()\u00bb (\u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f), \u00abuseSetRecoilState()\u00bb (\u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438) \u0438 \u0434\u0440. \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 Recoil, \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b \u0432 RecoilRoot. \u041f\u043e \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u044f\u043c, Recoil \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u0440\u043e\u043c\u0435\u0436\u0443\u0442\u043e\u0447\u043d\u043e\u0435 \u0437\u0432\u0435\u043d\u043e \u043c\u0435\u0436\u0434\u0443 useState() \u0438 Redux.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e \u00abrecoil\u00bb \u0434\u043b\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u0442\u0443\u0434\u0443\u0448\u043a\u0438 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c Recoil:<\/p>\n<pre><code class=\"bash\">yarn add recoil # \u0438\u043b\u0438 npm i recoil <\/code><\/pre>\n<p>  \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:<\/p>\n<pre><code class=\"plaintext\">|--recoil   |--modules     |--atoms       |--filterAtom.js       |--todosAtom.js     |--components       |--index.js       |--TodoControls.js       |--TodoFilters.js       |--TodoForm.js       |--TodoList.js       |--TodoListItem.js       |--TodoStats.js   |--App.js <\/code><\/pre>\n<p>  \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0430\u0442\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u0434\u0430\u0447:<\/p>\n<pre><code class=\"javascript\">\/\/ todosAtom.js \/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0442\u043e\u043c\u043e\u0432 \u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u0432 import { atom, selector } from 'recoil' \/\/ \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 import axios from 'axios'  \/\/ \u0430\u0434\u0440\u0435\u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 const SERVER_URL = 'http:\/\/localhost:5000\/todos'  \/\/ \u0430\u0442\u043e\u043c \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0434\u043b\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u0434\u0430\u0447 export const todosState = atom({   key: 'todosState',   default: selector({     key: 'todosState\/default',     get: async () =&gt; {       try {         const response = await axios(SERVER_URL)         return response.data       } catch (err) {         console.log(err.toJSON())       }     }   }) }) <\/code><\/pre>\n<p>  \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 Recoil \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043c\u0435\u0448\u0438\u0432\u0430\u0442\u044c \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0430\u0442\u043e\u043c\u043e\u0432 \u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u0432. \u041e\u043d \u0441\u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c React Suspense \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u043d\u0442\u0435\u043d\u0442\u0430 \u0434\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0430\u043a\u0436\u0435 \u0443 \u043d\u0430\u0441 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u044c (ErrorBoundary) \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0430 \u043e\u0448\u0438\u0431\u043e\u043a, \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0449\u0438\u0445 \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0430\u0442\u043e\u043c\u043e\u0432 \u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 src\/index.js \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">import React, { Component, Suspense } from 'react' import { render } from 'react-dom' \/\/ recoil import { RecoilRoot } from 'recoil'  \/\/ \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 import Loader from 'react-loader-spinner'  import App from '.\/recoil\/App'  \/\/ \u043f\u0440\u0435\u0434\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435\u043b\u044c \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430 React class ErrorBoundary extends Component {   constructor(props) {     super(props)     this.state = { error: null, errorInfo: null }   }    componentDidCatch(error, errorInfo) {     this.setState({       error: error,       errorInfo: errorInfo     })   }    render() {     if (this.state.errorInfo) {       return (         &lt;div&gt;           &lt;h2&gt;Something went wrong.&lt;\/h2&gt;           &lt;details style={{ whiteSpace: 'pre-wrap' }}&gt;             {this.state.error &amp;&amp; this.state.error.toString()}             &lt;br \/&gt;             {this.state.errorInfo.componentStack}           &lt;\/details&gt;         &lt;\/div&gt;       )     }     return this.props.children   } }  const loaderStyles = {   position: 'absolute',   top: '50%',   left: '50%',   transform: 'translate(-50%, -50%)' }  const root$ = document.getElementById('root') \/\/ \u043c\u044b \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432 Suspense, \u0437\u0430\u0442\u0435\u043c \u0432 ErrorBoundary render(   &lt;RecoilRoot&gt;     &lt;Suspense       fallback={         &lt;Loader           type='Oval'           color='#00bfff'           height={80}           width={80}           style={loaderStyles}         \/&gt;       }     &gt;       &lt;ErrorBoundary&gt;         &lt;App \/&gt;       &lt;\/ErrorBoundary&gt;     &lt;\/Suspense&gt;   &lt;\/RecoilRoot&gt;,   root$ ) <\/code><\/pre>\n<p>  \u0410\u0442\u043e\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">\/\/ filterAtom.js \/\/ recoil import { atom, selector } from 'recoil' \/\/ \u0430\u0442\u043e\u043c import { todosState } from '.\/todosAtom'  export const Filters = {   All: 'all',   Active: 'active',   Completed: 'completed' }  export const todoListFilterState = atom({   key: 'todoListFilterState',   default: Filters.All })  \/\/ \u0434\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0434\u0432\u0430 \u0430\u0442\u043e\u043c\u0430: \u0430\u0442\u043e\u043c \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u0438 \u0430\u0442\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0430 \u0437\u0430\u0434\u0430\u0447 export const filteredTodosState = selector({   key: 'filteredTodosState',   get: ({ get }) =&gt; {     const filter = get(todoListFilterState)     const todos = get(todosState)      if (filter === Filters.All) return todos      return filter === Filters.Completed       ? todos.filter((todo) =&gt; todo.completed)       : todos.filter((todo) =&gt; !todo.completed)   } }) <\/code><\/pre>\n<p>  \u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0430\u0442\u043e\u043c\u043e\u0432 \u0438 \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435 \u0445\u0443\u043a\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0434 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u00abTodoListItem\u00bb \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"javascript\">\/\/ \u0445\u0443\u043a import { useRecoilState } from 'recoil' \/\/ \u0441\u0442\u0438\u043b\u0438 import { ListGroup, Form, Button } from 'react-bootstrap' \/\/ \u0430\u0442\u043e\u043c import { todosState } from '..\/atoms\/todosAtom'  export const TodoListItem = ({ todo }) =&gt; {   \/\/ \u0434\u0430\u043d\u043d\u044b\u0439 \u0445\u0443\u043a - \u044d\u0442\u043e \u043a\u0430\u043a useState() \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f Recoil   const [todos, setTodos] = useRecoilState(todosState)   const { id, text, completed } = todo    const toggleTodo = () =&gt; {     const newTodos = todos.map((todo) =&gt;       todo.id === id ? { ...todo, completed: !todo.completed } : todo     )      setTodos(newTodos)   }    const updateTodo = ({ target: { value } }) =&gt; {     const trimmed = value.trim()      if (!trimmed) return      const newTodos = todos.map((todo) =&gt;       todo.id === id ? { ...todo, text: value } : todo     )      setTodos(newTodos)   }    const deleteTodo = () =&gt; {     const newTodos = todos.filter((todo) =&gt; todo.id !== id)      setTodos(newTodos)   }    const inputStyles = {     outline: 'none',     border: 'none',     background: 'none',     textAlign: 'center',     textDecoration: completed ? 'line-through' : '',     opacity: completed ? '0.8' : '1'   }    return (     &lt;ListGroup.Item className='d-flex align-items-baseline'&gt;       &lt;Form.Check type='checkbox' checked={completed} onChange={toggleTodo} \/&gt;       &lt;Form.Control         style={inputStyles}         defaultValue={text}         onChange={updateTodo}         disabled={completed}       \/&gt;       &lt;Button variant='danger' onClick={deleteTodo}&gt;         Delete       &lt;\/Button&gt;     &lt;\/ListGroup.Item&gt;   ) } <\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041a\u043e\u0434 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/b>                         <\/p>\n<div class=\"spoiler_text\">TodoControls.js:<\/p>\n<pre><code class=\"javascript\">\/\/ recoil import { useRecoilState } from 'recoil' \/\/ styles import { Container, ButtonGroup, Button } from 'react-bootstrap' \/\/ atom import { todosState } from '..\/atoms\/todosAtom'  export const TodoControls = () =&gt; {   const [todos, setTodos] = useRecoilState(todosState)    const completeAllTodos = () =&gt; {     const newTodos = todos.map((todo) =&gt; (todo.completed = true))      setTodos(newTodos)   }    const clearCompletedTodos = () =&gt; {     const newTodos = todos.filter((todo) =&gt; !todo.completed)      setTodos(newTodos)   }    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;Controls&lt;\/h4&gt;       &lt;ButtonGroup&gt;         &lt;Button variant='outline-secondary' onClick={completeAllTodos}&gt;           Complete all         &lt;\/Button&gt;         &lt;Button variant='outline-secondary' onClick={clearCompletedTodos}&gt;           Clear completed         &lt;\/Button&gt;       &lt;\/ButtonGroup&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoFilters.js:<\/p>\n<pre><code class=\"javascript\">\/\/ recoil import { useRecoilState } from 'recoil' \/\/ styles import { Container, Form } from 'react-bootstrap' \/\/ filters &amp; atom import { Filters, todoListFilterState } from '..\/atoms\/filterAtom'  export const TodoFilters = () =&gt; {   const [filter, setFilter] = useRecoilState(todoListFilterState)    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;Filters&lt;\/h4&gt;       {Object.keys(Filters).map((key) =&gt; {         const value = Filters[key]         const checked = value === filter          return (           &lt;Form.Check             key={value}             inline             label={value.toUpperCase()}             type='radio'             name='filter'             onChange={() =&gt; setFilter(value)}             checked={checked}           \/&gt;         )       })}     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoForm.js:<\/p>\n<pre><code class=\"javascript\">\/\/ react import { useState } from 'react' \/\/ recoil import { useSetRecoilState } from 'recoil' \/\/ libs import { nanoid } from 'nanoid' \/\/ styles import { Container, Form, Button } from 'react-bootstrap' \/\/ atom import { todosState } from '..\/atoms\/todosAtom'  export const TodoForm = () =&gt; {   const [text, setText] = useState('')   const setTodos = useSetRecoilState(todosState)    const updateText = ({ target: { value } }) =&gt; {     setText(value)   }    const addTodo = (e) =&gt; {     e.preventDefault()      const trimmed = text.trim()      if (trimmed) {       const newTodo = { id: nanoid(5), text, completed: false }        setTodos((oldTodos) =&gt; oldTodos.concat(newTodo))        setText('')     }   }    return (     &lt;Container className='mt-4'&gt;       &lt;h4&gt;Form&lt;\/h4&gt;       &lt;Form className='d-flex' onSubmit={addTodo}&gt;         &lt;Form.Control           type='text'           placeholder='Enter text...'           value={text}           onChange={updateText}         \/&gt;         &lt;Button variant='primary' type='submit'&gt;           Add         &lt;\/Button&gt;       &lt;\/Form&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoList.js:<\/p>\n<pre><code class=\"javascript\">\/\/ recoil import { useRecoilValue } from 'recoil' \/\/ components import { TodoListItem } from '.\/TodoListItem' \/\/ styles import { Container, ListGroup } from 'react-bootstrap' \/\/ atom import { filteredTodosState } from '..\/atoms\/filterAtom'  export const TodoList = () =&gt; {   const filteredTodos = useRecoilValue(filteredTodosState)    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;List&lt;\/h4&gt;       &lt;ListGroup&gt;         {filteredTodos.map((todo) =&gt; (           &lt;TodoListItem key={todo.id} todo={todo} \/&gt;         ))}       &lt;\/ListGroup&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  TodoStats.js:<\/p>\n<pre><code class=\"javascript\">\/\/ react import { useState, useEffect } from 'react' \/\/ recoil import { useRecoilValue } from 'recoil' \/\/ styles import { Container, ListGroup } from 'react-bootstrap' \/\/ atom import { todosState } from '..\/atoms\/todosAtom'  export const TodoStats = () =&gt; {   const todos = useRecoilValue(todosState)    const [stats, setStats] = useState({     total: 0,     active: 0,     completed: 0,     percent: 0   })    useEffect(() =&gt; {     if (todos.length) {       const total = todos.length       const completed = todos.filter((todo) =&gt; todo.completed).length       const active = total - completed       const percent = total === 0 ? 0 : Math.round((active \/ total) * 100) + '%'        setStats({         total,         active,         completed,         percent       })     }   }, [todos])    return (     &lt;Container className='mt-2'&gt;       &lt;h4&gt;Stats&lt;\/h4&gt;       &lt;ListGroup horizontal&gt;         {Object.entries(stats).map(([[first, ...rest], count], index) =&gt; (           &lt;ListGroup.Item key={index}&gt;             {first.toUpperCase() + rest.join('')}: {count}           &lt;\/ListGroup.Item&gt;         ))}       &lt;\/ListGroup&gt;     &lt;\/Container&gt;   ) } <\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0418\u0442\u0430\u043a, \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c. \u041a\u0430\u043a\u0438\u0435 \u0432\u044b\u0432\u043e\u0434\u044b \u043c\u043e\u0436\u043d\u043e \u0438\u0437 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c?<\/p>\n<p>  \u042f \u0432\u044b\u0441\u043a\u0430\u0436\u0443 \u0441\u0432\u043e\u0435 \u043c\u043d\u0435\u043d\u0438\u0435, \u043e\u043d\u043e \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0441\u0442\u0430\u0442\u0443\u0441 \u0438\u0441\u0442\u0438\u043d\u044b \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0438. \u0420\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f, \u0432\u044b\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0437\u0430\u0434\u0430\u0447, \u0440\u0435\u0448\u0430\u0435\u043c\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c:<\/p>\n<ul>\n<li>\u0414\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c (\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043e\u0434\u043d\u043e\u0433\u043e-\u0434\u0432\u0443\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432; \u043f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438, \u0447\u0442\u043e \u044d\u0442\u0438 \u0434\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0442\u0435\u0441\u043d\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u043c\u0435\u0436\u0434\u0443 \u0441\u043e\u0431\u043e\u0439) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 useState()<\/li>\n<li>\u0414\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c (\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0434\u0432\u0443\u0445 \u0438 \u0431\u043e\u043b\u0435\u0435 \u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432) \u0438\u043b\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0438 \u0441\u0440\u0435\u0434\u043d\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 Recoil \u0438\u043b\u0438 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0435 useContext()\/useReducer()<\/li>\n<li>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b, \u0442\u043e \u0432\u0430\u043c \u0432\u043f\u043e\u043b\u043d\u0435 \u0445\u0432\u0430\u0442\u0438\u0442 useContext() (useContext() \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435 \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c)<\/li>\n<li>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c (\u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0445 \u0438\u043b\u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432) \u0438\u043b\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 Redux Toolkit<\/li>\n<\/ul>\n<p>  \u0427\u0442\u043e \u043a\u0430\u0441\u0430\u0435\u0442\u0441\u044f MobX, \u0442\u043e \u044f \u0441\u043b\u044b\u0448\u0430\u043b \u043e \u043d\u0435\u043c \u043c\u043d\u043e\u0433\u043e \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e, \u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u043a\u0430\u043a \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u043e\u043a\u0430 \u043d\u0435 \u0443\u0441\u043f\u0435\u043b.<\/p>\n<p>  \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0438 \u0445\u043e\u0440\u043e\u0448\u0435\u0433\u043e \u0434\u043d\u044f.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/546632\/\"> https:\/\/habr.com\/ru\/post\/546632\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/98\/k9\/is\/98k9issmcul9hqqfqbjuflx57uo.png\"><\/p>\n<p>  \u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a, \u0434\u0440\u0443\u0437\u044c\u044f!<\/p>\n<p>  \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447. \u0427\u0442\u043e \u0432 \u043d\u0435\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u00ab\u0442\u0443\u0434\u0443\u0448\u043a\u0443\u00bb \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432 \u043a \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0432 React-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445: useState, useContext + useReducer, Redux Toolkit \u0438 Recoil.<\/p>\n<p>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0438 \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u0432\u0430\u0436\u0435\u043d \u0432\u044b\u0431\u043e\u0440 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0438\u043c.<\/p>\n<p>  \u0421\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u0435 \u0434\u043b\u044f \u043b\u044e\u0431\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438, \u0438\u043c\u0435\u044e\u0449\u0435\u0439 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044e. \u042d\u0442\u043e \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0442\u043e\u0442 \u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0437\u0430\u0434\u0430\u0447 \u0438\u043b\u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0442\u0430\u043a \u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043a\u0430\u043a \u0442\u0430\u043a\u043e\u0432\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u043b\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  \u0423\u0441\u043b\u043e\u0432\u043d\u043e, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435. \u041f\u043e\u0434 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c, \u043e\u0431\u044b\u0447\u043d\u043e, \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0432\u0437\u044f\u0442\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0412 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u0435\u0435 \u0438\u043c\u0435\u043d\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c \u0438\u043b\u0438 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u043c, \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u044f \u043f\u043e\u0434 \u044d\u0442\u0438\u043c \u0442\u043e, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043e\u0434\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c. \u0423\u0441\u043b\u043e\u0432\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0433\u0440\u0430\u0434\u0430\u0446\u0438\u0438 \u0432\u044b\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e useState(), \u043c\u043e\u0436\u0435\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0440\u043e\u043f\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c), \u0430 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 Redux, \u0433\u0434\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u0434\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435 \u0434\u043b\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043e\u0431\u044b\u0447\u043d\u043e, \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0441\u0440\u0435\u0437 (slice) \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 UI, \u0442\u043e\u0447\u043d\u0435\u0435, \u0434\u043b\u044f \u043b\u043e\u0433\u0438\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u044c\u044e).  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-319451","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=319451"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/319451\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=319451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=319451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=319451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}