{"id":306815,"date":"2020-07-12T21:00:39","date_gmt":"2020-07-12T21:00:39","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=306815"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=306815","title":{"rendered":"Todolist \u043d\u0430 React Hooks + TypeScript: \u043e\u0442 \u0441\u0431\u043e\u0440\u043a\u0438 \u0434\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/510642\/\">\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 16.9, \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 React JS \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u2014 <a href=\"https:\/\/reactjs.org\/docs\/hooks-intro.html\">\u0445\u0443\u043a\u0438<\/a>. \u041e\u043d\u0438 \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 React, \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u044f \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 \u0445\u0443\u043a\u0430\u043c\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 Todolist \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 React Hooks \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/react.html\">TypeScript<\/a>.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>\u0421\u0431\u043e\u0440\u043a\u0430<\/h2>\n<p>  \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f:<\/p>\n<p>  \u251c\u2500\u2500 src<br \/>  | \u251c\u2500\u2500 components<br \/>  | \u251c\u2500\u2500 index.html<br \/>  | \u251c\u2500\u2500 index.tsx<br \/>  \u251c\u2500\u2500 package.json<br \/>  \u251c\u2500\u2500 tsconfig.json<br \/>  \u251c\u2500\u2500 webpack.config.json<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0424\u0430\u0439\u043b package.json:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"json\">{   &quot;name&quot;: &quot;todo-react-typescript&quot;,   &quot;version&quot;: &quot;1.0.0&quot;,   &quot;description&quot;: &quot;&quot;,   &quot;main&quot;: &quot;index.tsx&quot;,   &quot;scripts&quot;: {     &quot;start&quot;: &quot;webpack-dev-server --port 3000 --mode development --open --hot&quot;,     &quot;build&quot;: &quot;webpack --mode production&quot;   },   &quot;author&quot;: &quot;&quot;,   &quot;license&quot;: &quot;ISC&quot;,   &quot;devDependencies&quot;: {     &quot;ts-loader&quot;: &quot;^5.2.1&quot;,     &quot;html-webpack-plugin&quot;: &quot;^3.2.0&quot;,     &quot;typescript&quot;: &quot;^3.8.2&quot;,     &quot;webpack&quot;: &quot;^4.41.6&quot;,     &quot;webpack-cli&quot;: &quot;^3.3.11&quot;,     &quot;webpack-dev-server&quot;: &quot;^3.10.3&quot;   },   &quot;dependencies&quot;: {     &quot;@types\/react&quot;: &quot;^16.9.23&quot;,     &quot;@types\/react-dom&quot;: &quot;^16.9.5&quot;,     &quot;react&quot;: &quot;^16.12.0&quot;,     &quot;react-dom&quot;: &quot;^16.12.0&quot;   } }<\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 TypeScript, \u043f\u043e\u043c\u0438\u043c\u043e \u043f\u0430\u043a\u0435\u0442\u0430 typescript, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c ts-loader, \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 tsx-\u0444\u0430\u0439\u043b\u044b \u0432 js-\u043a\u043e\u0434, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0430\u043a\u0435\u0442\u044b \u0441\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f React \u2014 @types\/react \u0438 @types\/react-dom. \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u0430\u0432\u0438\u043c html-webpack-plugin, \u043e\u043d \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 dev-\u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0440\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0438 index.html \u2014 \u0444\u0430\u0439\u043b\u0430 \u0432 \u043a\u043e\u0440\u043d\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430, \u0438 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043b\u044f production-\u0441\u0431\u043e\u0440\u043a\u0438 \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435.  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0424\u0430\u0439\u043b tsconfig.json:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"json\">{   &quot;compilerOptions&quot;: {     &quot;sourceMap&quot;: true,     &quot;noImplicitAny&quot;: false,     &quot;module&quot;: &quot;commonjs&quot;,     &quot;target&quot;: &quot;es6&quot;,     &quot;lib&quot;: [       &quot;es2015&quot;,       &quot;es2017&quot;,       &quot;dom&quot;     ],     &quot;removeComments&quot;: true,     &quot;allowSyntheticDefaultImports&quot;: false,     &quot;jsx&quot;: &quot;react&quot;,     &quot;allowJs&quot;: true,     &quot;baseUrl&quot;: &quot;.\/&quot;,     &quot;paths&quot;: {       &quot;components\/*&quot;: [         &quot;src\/components\/*&quot;       ]     }   } }<\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0435 \u00abjsx\u00bb \u0437\u0430\u0434\u0430\u0451\u0442 \u0440\u0435\u0436\u0438\u043c \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430. \u0412\u0441\u0435\u0433\u043e \u0435\u0441\u0442\u044c 3 \u0440\u0435\u0436\u0438\u043c\u0430: \u00abpreserve\u00bb, \u00abreact\u00bb \u0438 \u00abreact-native\u00bb. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/t6\/su\/tg\/t6sutgkry4n7oo6lshk4refsa9o.png\"\/>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0424\u0430\u0439\u043b webpack.config.json:<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"json\">const path = require('path'); const HtmlWebpackPlugin = require('html-webpack-plugin');  module.exports = {     entry: '.\/src\/index.tsx',     resolve: {         extensions: ['.ts', '.tsx', '.js']     },     output: {         path: path.join(__dirname, '\/dist'),         filename: 'bundle.min.js'     },     module: {         rules: [             {                 test: \/\\.ts(x?)$\/,                 exclude: \/node_modules\/,                 use: [                     {                         loader: &quot;ts-loader&quot;                     }                 ]             }         ]     },     plugins: [         new HtmlWebpackPlugin({             template: '.\/src\/index.html'         })     ] };<\/code><\/pre>\n<p>  \u0422\u043e\u0447\u043a\u0430 \u0432\u0445\u043e\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u2014 .\/src\/index.tsx. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e resolve.extensions \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c ts\/tsx\/js \u0444\u0430\u0439\u043b\u044b. \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c ts-loader \u0438 html-webpack-plugin. \u0421\u0431\u043e\u0440\u043a\u0430 \u0433\u043e\u0442\u043e\u0432\u0430.  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h2>\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430<\/h2>\n<p>  \u0412 \u0444\u0430\u0439\u043b\u0435 index.html \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440, \u043a\u0443\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u0442\u044c\u0441\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435: <\/p>\n<pre><code class=\"xml\">&lt;div id=&quot;root&quot;&gt;&lt;\/div&gt;<\/code><\/pre>\n<p>  \u0412 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 components \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0430\u0448 \u043f\u0435\u0440\u0432\u044b\u0439 \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u043f\u0443\u0441\u0442\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u2014 App.tsx.<br \/>  \u0424\u0430\u0439\u043b index.tsx: <\/p>\n<pre><code class=\"javascript\">import * as React from 'react'; import * as ReactDOM from 'react-dom';  import App from &quot;.\/components\/App&quot;;  ReactDOM.render (     &lt;App\/&gt;,     document.getElementById(&quot;root&quot;) );<\/code><\/pre>\n<p>  Todolist-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c:<\/p>\n<ul>\n<li> \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 <\/li>\n<li> \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443 <\/li>\n<li> \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0443\u0441 \u0437\u0430\u0434\u0430\u0447\u0438 (\u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \/ \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430) <\/li>\n<\/ul>\n<p>  \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0442\u0430\u043a: \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 + \u043a\u043d\u043e\u043f\u043a\u0430 \u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u0438 \u043d\u0438\u0436\u0435 \u2014 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0417\u0430\u0434\u0430\u0447\u0438 \u043c\u043e\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0438\u043c \u0441\u0442\u0430\u0442\u0443\u0441. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/g6\/5c\/c9\/g65cc9fyo10kro8sochcv_i4jus.png\"\/><\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0433\u043e \u043d\u0430 \u0434\u0432\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u2014 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0441\u043f\u0438\u0441\u043e\u043a \u0432\u0441\u0435\u0445 \u0437\u0430\u0434\u0430\u0447. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 App.tsx \u043d\u0430 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0432\u0438\u0434: <\/p>\n<pre><code class=\"javascript\">import * as React from 'react'; import NewTask from &quot;.\/NewTask&quot;; import TasksList from &quot;.\/TasksList&quot;;  const App = () =&gt; {      return (         &lt;&gt;             &lt;NewTask \/&gt;             &lt;TasksList \/&gt;         &lt;\/&gt;     ) }  export default App;<\/code><\/pre>\n<p>  \u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0438 \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043f\u0443\u0441\u0442\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b NewTask \u0438 TasksList. \u0422\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438, \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c. \u0412 React \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u0432\u0430 \u043f\u043e\u0434\u0445\u043e\u0434\u0430 \u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044e \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438:<\/p>\n<ol>\n<li> \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0432\u0441\u0435\u0445 \u0435\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0432 App.tsx) \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c \u0447\u0435\u0440\u0435\u0437 \u043f\u0440\u043e\u043f\u0441\u044b (\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0441\u043f\u043e\u0441\u043e\u0431);<\/li>\n<li> \u0425\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0438 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u2014 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u043c, \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0432 \u043d\u0435\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u044b \u0438 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 (\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0445\u0443\u043a\u0430 useContext).<\/li>\n<\/ol>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0438 \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u043a\u0430\u0436\u0435\u043c\u0441\u044f \u043e\u0442 \u043f\u0440\u043e\u043f\u0441\u043e\u0432. <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">TypeScript \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0435 \u043f\u0440\u043e\u043f\u0441\u043e\u0432<\/b>                         <\/p>\n<div class=\"spoiler_text\"><i>* \u0415\u0441\u043b\u0438 \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u0441\u0451 \u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u043f\u0441\u044b, TypeScript \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u044f\u0432\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430: <\/p>\n<pre><code class=\"javascript\">const NewTask: React.FC&lt;MyProps&gt; = ({taskName}) =&gt; {...<\/code><\/pre>\n<p>  \u0422\u0438\u043f React.FC, \u044f\u0432\u043b\u044f\u044f\u0441\u044c \u0434\u0436\u0435\u043d\u0435\u0440\u0438\u043a\u043e\u043c, \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 (\u0438\u043b\u0438 \u0442\u0438\u043f) \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432: <\/p>\n<pre><code class=\"javascript\">interface MyProps {     taskName: String; }<\/code><\/pre>\n<p><\/i>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h3>useContext<\/h3>\n<p>   \u0418\u0442\u0430\u043a, \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0441\u0442\u0435\u0439\u0442\u0430 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0445\u0443\u043a\u043e\u043c useContext. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043b\u044e\u0431\u043e\u043c \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432, \u043e\u0431\u0435\u0440\u043d\u0443\u0442\u044b\u0445 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u043e\u043c. <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f useContext<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"javascript\">import * as React from 'react'; import {useContext} from &quot;react&quot;;  interface Person {     name: String,     surname: String }  export const PersonContext = React.createContext&lt;Partial&lt;Person&gt;&gt;({});  const PersonWrapper = () =&gt; {      const person: Person = {         name: 'Spider',         surname: 'Man'     }      return (         &lt;&gt;             &lt;PersonContext.Provider value={ person }&gt;                 &lt;PersonComponent \/&gt;             &lt;\/PersonContext.Provider&gt;         &lt;\/&gt;     ) }  const PersonComponent = () =&gt; {     const person = useContext(PersonContext);     return (         &lt;div&gt;             Hello, {person.name} {person.surname}!         &lt;\/div&gt;     ) }  export default PersonWrapper;<\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u2014 \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044f name \u0438 surname, \u043e\u0431\u0430 \u0442\u0438\u043f\u0430 String.<\/p>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043c\u0435\u0442\u043e\u0434\u043e\u043c createContext \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u043d\u0435\u0433\u043e \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u043f\u0443\u0441\u0442\u043e\u0439 \u043e\u0431\u044a\u0435\u043a\u0442. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b TypeScript \u00ab\u043d\u0435 \u0440\u0443\u0433\u0430\u043b\u0441\u044f\u00bb \u043d\u0430 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430, \u0435\u0441\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f Partial \u2014 \u043e\u043d \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u043f\u043e\u043b\u0435\u0439. <\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u2014 \u043e\u0431\u044a\u0435\u043a\u0442 person, \u0438 \u0432\u043d\u0443\u0442\u0440\u044c \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0422\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0432 \u043b\u044e\u0431\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u043c \u0432\u043d\u0443\u0442\u0440\u044c \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430. \u0412\u044b\u0437\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0445\u0443\u043a\u0430 useContext.  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h3>useReducer<\/h3>\n<p>  \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f useReducer \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f.<\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e useReducer<\/b>                         <\/p>\n<div class=\"spoiler_text\"> \u0425\u0443\u043a useReducer \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0442\u0435\u0439\u0442\u043e\u043c \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0430 \u043e\u0434\u043d\u043e\u0439 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438: \u043f\u043e \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044e, \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u0432 \u043f\u043e\u043b\u0435 type, \u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u2014 \u0432 \u043f\u043e\u043b\u0435 payload. \u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438: <\/p>\n<pre><code class=\"javascript\">import * as React from 'react'; import {useReducer} from &quot;react&quot;;  interface PersonState {     name: String,     surname: String }  interface PersonAction {     type: 'CHANGE',     payload: PersonState }   const personReducer = (state: PersonState, action: PersonAction): PersonState =&gt; {     switch (action.type) {         case 'CHANGE':             return action.payload;         default: throw new Error('Unexpected action');     } }   const PersonComponent = () =&gt; {      const initialState = {         name: 'Unknown',         surname: 'Guest'     }      const [person, changePerson] = useReducer&lt;React.Reducer&lt;PersonState, PersonAction&gt;&gt;(personReducer, initialState);      return (         &lt;div onClick={() =&gt; changePerson({type: 'CHANGE', payload: {name: 'Jackie', surname: 'Chan'}})}&gt;             Hello, {person.name} {person.surname}!         &lt;\/div&gt;     ) }  export default PersonComponent;<\/code><\/pre>\n<p>  \u0412 useReducer \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440 personReducer, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 changePerson. <\/p>\n<p>  \u0412 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 person \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u0430\u043d initialState, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e \u0445\u043e\u0434\u0443 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 changePerson \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u043c \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c. <\/p>\n<p>  \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 CHANGE, \u043d\u043e \u043f\u043b\u044e\u0441 \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440\u0430 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c: <\/p>\n<pre><code class=\"javascript\">case 'CHANGE':    return action.payload; case 'CLEAR':    return {       name: 'Undefined',       surname: 'Undefined'    };<\/code><\/pre>\n<p>  <\/div>\n<\/p><\/div>\n<p>  <\/p>\n<h3>useContext + useReducer<\/h3>\n<p>  \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0437\u0430\u043c\u0435\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 Redux \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430 \u0432 \u0441\u0432\u044f\u0437\u043a\u0435 \u0441 useReducer. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0445\u0443\u043a\u0430 useReducer \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u0438\u043c \u0441\u0442\u0435\u0439\u0442 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0435\u0433\u043e \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u044d\u0442\u0438 \u0445\u0443\u043a\u0438 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:<\/p>\n<pre><code class=\"javascript\">import * as React from 'react';  import {useReducer} from &quot;react&quot;; import {Action, State, ContextState} from &quot;..\/types\/stateType&quot;; import NewTask from &quot;.\/NewTask&quot;; import TasksList from &quot;.\/TasksList&quot;;  \/\/ \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0435\u0439\u0442\u0430 export const initialState: State = {     newTask: '',     tasks: [] }  \/\/ &lt;Partial&gt; \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0431\u0435\u0437 \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 export const ContextApp = React.createContext&lt;Partial&lt;ContextState&gt;&gt;({});  \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0442\u0435\u0439\u0442 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442 Action \u0441 \u043f\u043e\u043b\u044f\u043c\u0438 type \u0438 payload, \u0442\u0438\u043f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0433\u043e \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f - State export const todoReducer = (state: State, action: Action):State =&gt; {     switch (action.type) {         case ActionType.ADD: {             return {...state, tasks: [...state.tasks, {                     name: action.payload,                     isDone: false                 }]}         }         case ActionType.CHANGE: {             return {...state, newTask: action.payload}         }         case ActionType.REMOVE: {             return {...state, tasks:  [...state.tasks.filter(task =&gt; task !== action.payload)]}         }         case ActionType.TOGGLE: {             return {...state, tasks: [...state.tasks.map((task) =&gt; (task !== action.payload ? task : {...task, isDone: !task.isDone}))]}         }         default: throw new Error('Unexpected action');     } };  const App:  React.FC = () =&gt; { \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 todoReducer, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 \u0435\u0433\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0432 useReduser. \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0432 \u0441\u0442\u0435\u0439\u0442 \u043f\u043e\u043f\u0430\u0434\u0451\u0442 initialState, \u0438 \u0434\u0430\u043b\u0435\u0435 \u043f\u0440\u0438 \u0434\u0438\u0441\u043f\u0430\u0442\u0447\u0435 (changeState) \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c\u0441\u044f.     const [state, changeState] = useReducer&lt;React.Reducer&lt;State, Action&gt;&gt;(todoReducer, initialState);      const ContextState: ContextState = {         state,         changeState     };  \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b useReducer - \u0441\u0442\u0435\u0439\u0442 \u0438 \u043c\u0435\u0442\u043e\u0434 \u0435\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f     return (         &lt;&gt;             &lt;ContextApp.Provider value={ContextState}&gt;                 &lt;NewTask \/&gt;                 &lt;TasksList \/&gt;             &lt;\/ContextApp.Provider&gt;         &lt;\/&gt;     ) }  export default App;<\/code><\/pre>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0439 \u043e\u0442 \u043a\u043e\u0440\u043d\u0435\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0441\u0442\u0435\u0439\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438 \u043c\u0435\u043d\u044f\u0442\u044c \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440\u0430.<\/p>\n<h3>Typescript. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u043e\u0432 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h3>\n<p>  \u0412 \u0444\u0430\u0439\u043b\u0435 stateType \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c TypeScript-\u0442\u0438\u043f\u044b \u0434\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"javascript\">import {Dispatch} from &quot;react&quot;;  \/\/ \u0421\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0438\u043c\u0435\u0435\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0438 \u0441\u0442\u0430\u0442\u0443\u0441 \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u0438 export type Task = {     name: string;     isDone: boolean }  export type Tasks = Task[];  \/\/ \u0412 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u0432 \u0438\u043d\u043f\u0443\u0442 \u043d\u043e\u0432\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 \u0443\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447 export type State = {     newTask: string;     tasks: Tasks }  \/\/ \u0412\u0441\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 \u0441\u043e \u0441\u0442\u0435\u0439\u0442\u043e\u043c export enum ActionType {     ADD = 'ADD',     CHANGE = 'CHANGE',     REMOVE = 'REMOVE',     TOGGLE = 'TOGGLE' }  \/\/ \u0414\u043b\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 ADD \u0438 CHANGE \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0440\u043e\u043a\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 type ActionStringPayload = {     type: ActionType.ADD | ActionType.CHANGE,     payload: string }  \/\/ \u0414\u043b\u044f \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439 TOGGLE \u0438 REMOVE \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0438\u043f\u0430 Task type ActionObjectPayload = {     type: ActionType.TOGGLE | ActionType.REMOVE,     payload: Task }  \/\/ \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0434\u0432\u0435 \u0433\u0440\u0443\u043f\u043f\u044b \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440\u0435 export type Action = ActionStringPayload | ActionObjectPayload;  \/\/ \u041d\u0430\u0448 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0441\u0442\u0435\u0439\u0442\u0430 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0443\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f Action. \u0422\u0438\u043f Dispatch \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 react export type ContextState = {     state: State;     changeState: Dispatch&lt;Action&gt; }<\/code><\/pre>\n<p>  <\/p>\n<h3>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0430<\/h3>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c state \u0433\u043e\u0442\u043e\u0432 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 NewTask.tsx:<\/p>\n<pre><code class=\"javascript\">import * as React from 'react';  import {useContext} from &quot;react&quot;; import {ContextApp} from &quot;.\/App&quot;;  import {TaskName} from &quot;..\/types\/taskType&quot;; import {ActionType} from &quot;..\/types\/stateType&quot;;  const NewTask: React.FC = () =&gt; { \/\/ \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c state \u0438 dispatch-\u043c\u0435\u0442\u043e\u0434     const {state, changeState} = useContext(ContextApp);  \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0434\u0432\u0430 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440\u0443 todoReducer - \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438\u043d\u043f\u0443\u0442\u0430. \u041f\u043e\u0441\u043b\u0435 \u0438\u0445 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f state \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u0441\u044f. \u0414\u043b\u044f \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u043c\u0438 React-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438     const addTask = (event: React.FormEvent&lt;HTMLFormElement&gt;, task: TaskName) =&gt; {         event.preventDefault();         changeState({type: ActionType.ADD, payload: task})         changeState({type: ActionType.CHANGE, payload: ''})     }  \/\/ \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e - \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0438\u043d\u043f\u0443\u0442\u0435     const changeTask = (event: React.ChangeEvent&lt;HTMLInputElement&gt;) =&gt; {         changeState({type: ActionType.CHANGE, payload: event.target.value})     }      return (         &lt;&gt;             &lt;form onSubmit={(event)=&gt;addTask(event, state.newTask)}&gt;                 &lt;input type='text' onChange={(event)=&gt;changeTask(event)} value={state.newTask}\/&gt;                 &lt;button type=&quot;submit&quot;&gt;Add a task&lt;\/button&gt;             &lt;\/form&gt;         &lt;\/&gt;     ) };  export default NewTask; <\/code><\/pre>\n<p>  TasksList.tsx:<\/p>\n<pre><code class=\"javascript\">import * as React from 'react';  import {Task} from &quot;..\/types\/taskType&quot;; import {ActionType} from &quot;..\/types\/stateType&quot;; import {useContext} from &quot;react&quot;; import {ContextApp} from &quot;.\/App&quot;;  const TasksList: React.FC = () =&gt; { \/\/ \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0434\u0438\u0441\u043f\u0430\u0442\u0447 (\u043d\u0430\u0437\u0432\u0430\u043d\u043d\u044b\u0439 changeState)     const {state, changeState} = useContext(ContextApp);      const removeTask = (taskForRemoving: Task) =&gt; {         changeState({type: ActionType.REMOVE, payload: taskForRemoving})     }     const toggleReadiness = (taskForChange: Task) =&gt; {         changeState({type: ActionType.TOGGLE, payload: taskForChange})     }      return (         &lt;&gt;             &lt;ul&gt;                 {state.tasks.map((task,i)=&gt;(                     &lt;li key={i} className={task.isDone ? 'ready' : null}&gt;                         &lt;label&gt;                             &lt;input type=&quot;checkbox&quot; onChange={()=&gt;toggleReadiness(task)} checked={task.isDone}\/&gt;                         &lt;\/label&gt;                         &lt;div className=&quot;task-name&quot;&gt;                             {task.name}                         &lt;\/div&gt;                         &lt;button className='remove-button' onClick={()=&gt;removeTask(task)}&gt;                             X                         &lt;\/button&gt;                     &lt;\/li&gt;                 ))}             &lt;\/ul&gt;         &lt;\/&gt;     ) };  export default TasksList;<\/code><\/pre>\n<p>  \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u043e! \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e.<\/p>\n<h2>\u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f <a href=\"https:\/\/jestjs.io\/docs\/en\/api\">Jest<\/a> + Enzyme, \u0430 \u0442\u0430\u043a\u0436\u0435 <a href=\"https:\/\/testing-library.com\/docs\/intro\">@testing-library\/react<\/a>.<br \/>  \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c dev-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"javascript\">&quot;@testing-library\/react&quot;: &quot;^10.4.3&quot;, &quot;@testing-library\/react-hooks&quot;: &quot;^3.3.0&quot;, &quot;@types\/enzyme&quot;: &quot;^3.10.5&quot;, &quot;@types\/jest&quot;: &quot;^24.9.1&quot;, &quot;enzyme&quot;: &quot;^3.11.0&quot;, &quot;enzyme-adapter-react-16&quot;: &quot;^1.15.2&quot;, &quot;enzyme-to-json&quot;: &quot;^3.3.4&quot;, &quot;jest&quot;: &quot;^26.1.0&quot;, &quot;ts-jest&quot;: &quot;^26.1.1&quot;,<\/code><\/pre>\n<p>  \u0412 package.json \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0434\u043b\u044f jest: <\/p>\n<pre><code class=\"javascript\"> &quot;jest&quot;: {     &quot;preset&quot;: &quot;ts-jest&quot;,     &quot;setupFiles&quot;: [       &quot;.\/src\/__tests__\/setup.ts&quot;     ],     &quot;snapshotSerializers&quot;: [       &quot;enzyme-to-json\/serializer&quot;     ],     &quot;testRegex&quot;: &quot;\/__tests__\/.*\\\\.test.(ts|tsx)$&quot;,     &quot;moduleFileExtensions&quot;: [       &quot;ts&quot;,       &quot;tsx&quot;,       &quot;js&quot;,       &quot;jsx&quot;,       &quot;json&quot;,       &quot;node&quot;     ]   },<\/code><\/pre>\n<p>  \u0438 \u0432 \u0431\u043b\u043e\u043a\u0435 \u00abscripts\u00bb \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432: <\/p>\n<pre><code class=\"javascript\">&quot;test&quot;: &quot;jest&quot;<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 src \u043d\u043e\u0432\u044b\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 __tests__ \u0438 \u0432 \u043d\u0435\u043c \u2014 \u0444\u0430\u0439\u043b setup.ts \u0441 \u0442\u0430\u043a\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c: <\/p>\n<pre><code class=\"javascript\">import {configure} from 'enzyme'; import * as ReactSixteenAdapter from 'enzyme-adapter-react-16'; const adapter = ReactSixteenAdapter as any;  configure({ adapter: new adapter() });<\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b todoReducer.test.ts, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440: <\/p>\n<pre><code class=\"javascript\">import {todoReducer} from &quot;..\/reducers\/todoReducer&quot;; import {ActionType, Action, State} from &quot;..\/types\/stateType&quot;; import {Task} from &quot;..\/types\/taskType&quot;;  describe('todoReducer',()=&gt;{     it('returns new state for &quot;ADD&quot; type', () =&gt; { \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0442\u0435\u0439\u0442 \u0441 \u043f\u0443\u0441\u0442\u044b\u043c \u043c\u0430\u0441\u0441\u0438\u0432\u043e\u043c \u0437\u0430\u0434\u0430\u0447         const initialState: State = {newTask: '', tasks: []}; \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 'ADD' \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u043d\u0435\u0433\u043e \u0442\u0435\u043a\u0441\u0442 'new task'         const updateAction: Action = {type: ActionType.ADD, payload: 'new task'}; \/\/ \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440 \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441\u0442\u0435\u0439\u0442\u043e\u043c \u0438 \u044d\u043a\u0448\u0435\u043d\u043e\u043c         const updatedState = todoReducer(initialState, updateAction); \/\/ \u041e\u0436\u0438\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0441\u0442\u0435\u0439\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443         expect(updatedState).toEqual({newTask: '', tasks: [{name: 'new task', isDone: false}]});     });      it('returns new state for &quot;REMOVE&quot; type', () =&gt; {         const task: Task = {name: 'new task', isDone: false}         const initialState: State = {newTask: '', tasks: [task]};         const updateAction: Action = {type: ActionType.REMOVE, payload: task};         const updatedState = todoReducer(initialState, updateAction);         expect(updatedState).toEqual({newTask: '', tasks: []});     });      it('returns new state for &quot;TOGGLE&quot; type', () =&gt; {         const task: Task = {name: 'new task', isDone: false}         const initialState: State = {newTask: '', tasks: [task]};         const updateAction: Action = {type: ActionType.TOGGLE, payload: task};         const updatedState = todoReducer(initialState, updateAction);         expect(updatedState).toEqual({newTask: '', tasks: [{name: 'new task', isDone: true}]});     });      it('returns new state for &quot;CHANGE&quot; type', () =&gt; {         const initialState: State = {newTask: '', tasks: []};         const updateAction: Action = {type: ActionType.CHANGE, payload: 'new task'};         const updatedState = todoReducer(initialState, updateAction);         expect(updatedState).toEqual({newTask: 'new task', tasks: []});     }); }) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0435\u043c\u0443 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0441\u0442\u0435\u0439\u0442 \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435, \u0438 \u0437\u0430\u0442\u0435\u043c \u043b\u043e\u0432\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0435\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 App.tsx, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0440\u0435\u0434\u044c\u044e\u0441\u0435\u0440\u0430, \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u0437 \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a. \u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b App.test.tsx:<\/p>\n<pre><code class=\"javascript\">import * as React from 'react'; import {shallow} from 'enzyme'; import {fireEvent, render, cleanup} from &quot;@testing-library\/react&quot;; import App from &quot;..\/components\/App&quot;;  describe('&lt;App \/&gt;', () =&gt; { \/\/ jest-\u0444\u0443\u043d\u043a\u0446\u0438\u044f afterEach \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c \u043a\u043e\u043b\u043b\u0431\u0435\u043a\u043e\u043c cleanup \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u0438 \u043e\u0447\u0438\u0449\u0430\u0435\u0442 \u0441\u0440\u0435\u0434\u0443 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f     afterEach(cleanup);      it('hasn`t got changes', () =&gt; { \/\/  \u043c\u0435\u0442\u043e\u0434 shallow \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 enzyme \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u044e\u043d\u0438\u0442-\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u0431\u0435\u0437 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432.          const component = shallow(&lt;App \/&gt;); \/\/ \u041f\u0440\u0438 \u043f\u0435\u0440\u0432\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0442\u0435\u0441\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u043d \u0441\u043d\u0438\u043c\u043e\u043a \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c\u0441\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u044c \u0441\u043d\u0438\u043c\u043a\u0430 \u0441 \u0442\u0435\u043a\u0443\u0449\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u0414\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f snapshots \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0442\u0435\u0441\u0442 \u0441 \u0444\u043b\u0430\u0433\u043e\u043c -u: jest -u         expect(component).toMatchSnapshot();     });  \/\/ \u0422\u0430\u043a \u043a\u0430\u043a \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043d\u0430 DOM-\u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u0445), \u043e\u0431\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0442\u0435\u0441\u0442 \u0432 async     it('should render right input value',  async () =&gt; { \/\/ render() \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 @testing-library\/react&quot; \u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 shallow() \u0442\u0435\u043c, \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u0438\u0442 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0435 DOM-\u0434\u0435\u0440\u0435\u0432\u043e \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f container  \u2014 \u044d\u0442\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 div, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0432\u0435\u0434\u0435\u043d \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.         const { container } = render(&lt;App\/&gt;);         expect(container.querySelector('input').getAttribute('value')).toEqual(''); \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0438\u043d\u043f\u0443\u0442\u0430 \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0442\u0443\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 'test'         fireEvent.change(container.querySelector('input'), {             target: {                 value: 'test'             },         }) \/\/ \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0438\u043d\u043f\u0443\u0442\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 'test'         expect(container.querySelector('input').getAttribute('value')).toEqual('test'); \/\/ \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043a\u043b\u0438\u043a\u0430 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0438 \u043f\u043e\u043b\u0435 \u0438\u043d\u043f\u0443\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u043e\u0447\u0438\u0449\u0430\u0442\u044c\u0441\u044f         fireEvent.click(container.querySelector('button')) \/\/ \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0438\u043d\u043f\u0443\u0442\u0435 \u043f\u0443\u0441\u0442\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 value         expect(container.querySelector('input').getAttribute('value')).toEqual('');     }); }) <\/code><\/pre>\n<p>  \u0412 TasksList \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043b\u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0439 \u0441\u0442\u0435\u0439\u0442. \u0424\u0430\u0439\u043b TasksList.test.tsx:<\/p>\n<pre><code class=\"javascript\">import * as React from 'react'; import {ContextApp, initialState} from &quot;..\/components\/App&quot;;  import {shallow} from &quot;enzyme&quot;; import {cleanup, render} from &quot;@testing-library\/react&quot;;  import TasksList from &quot;..\/components\/TasksList&quot;; import {State} from &quot;..\/types\/stateType&quot;;  describe('&lt;TasksList \/&gt;',() =&gt; {      afterEach(cleanup);  \/\/ \u0421\u043e\u0437\u0434\u0430\u0451\u043c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u0442\u0435\u0439\u0442     const testState: State = {         newTask: '',         tasks: [{name: 'test', isDone: false}, {name: 'test2', isDone: false}]     }  \/\/ \u041f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 ContextApp \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u0442\u0435\u0439\u0442     const Wrapper = () =&gt; {         return (             &lt;ContextApp.Provider value={{state: testState}}&gt;                 &lt;TasksList\/&gt;             &lt;\/ContextApp.Provider&gt;             )     }      it('should render right tasks length', async () =&gt; {         const {container} = render(&lt;Wrapper\/&gt;);  \/\/ \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0434\u043b\u0438\u043d\u0443 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430         expect(container.querySelectorAll('li')).toHaveLength(testState.tasks.length);     });  })<\/code><\/pre>\n<p>  \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043f\u043e\u043b\u044f newTask \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 NewTask, \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u044f value \u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 input. <\/p>\n<p>  \u041f\u0440\u043e\u0435\u043a\u0442 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0441 <a href=\"https:\/\/github.com\/Irinova\/todo-react-typescript.git\">GitGub-\u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f<\/a>.<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451, \u0441\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435.<\/p>\n<h2>\u0420\u0435\u0441\u0443\u0440\u0441\u044b<\/h2>\n<p>  <a href=\"https:\/\/reactjs.org\/docs\/hooks-intro.html\">React JS. \u0425\u0443\u043a\u0438<\/a><br \/>  <a href=\"https:\/\/www.toptal.com\/react\/react-hooks-typescript-example\">Working with React Hooks and TypeScript<\/a><\/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\/510642\/\"> https:\/\/habr.com\/ru\/post\/510642\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/510642\/\">\u041d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0432\u0435\u0440\u0441\u0438\u0438 16.9, \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 React JS \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u043d\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u2014 <a href=\"https:\/\/reactjs.org\/docs\/hooks-intro.html\">\u0445\u0443\u043a\u0438<\/a>. \u041e\u043d\u0438 \u0434\u0430\u044e\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 React, \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u044f \u043e\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u043d\u043e \u0441 \u0445\u0443\u043a\u0430\u043c\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0432\u0435\u0440\u0441\u0438\u0438 Todolist \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 React Hooks \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <a href=\"https:\/\/www.typescriptlang.org\/docs\/handbook\/react.html\">TypeScript<\/a>.  <\/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-306815","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306815","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=306815"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/306815\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=306815"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=306815"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=306815"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}