{"id":364666,"date":"2024-05-21T02:21:46","date_gmt":"2024-05-21T02:21:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=364666"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=364666","title":{"rendered":"<span>\u041a\u0430\u043a \u044f \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0431\u0435\u0437 \u0445\u0443\u043a\u043e\u0432 \u043d\u0430 react<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0425\u0443\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439. \u041e\u043d\u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u0435\u0440\u0435\u0440\u0438\u0441\u043e\u0432\u043a\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438 \u043e\u0442\u0447\u0430\u0441\u0442\u0438 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438. \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0438\u0445?<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443.<\/p>\n<pre><code class=\"typescript\">import { useState } from \"react\"  const Component: React.FC = () => { \u00a0 const [count, setCount] = useState(0)  \u00a0 const handleIncrement = () => { \u00a0 \u00a0 setCount((c) => c + 1) \u00a0 }  \u00a0 return ( \u00a0 \u00a0 &lt;div> \u00a0 \u00a0 \u00a0 &lt;div data-testid=\"count\">count: {count}&lt;\/div> \u00a0 \u00a0 \u00a0 &lt;button data-testid=\"increment\" onClick={handleIncrement}>increment&lt;\/button> \u00a0 \u00a0 &lt;\/div> \u00a0 ) } <\/code><\/pre>\n<p>\u0427\u0435\u0440\u0435\u0437 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0440\u043e\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u043c \u043d\u0430\u0448\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435.<\/p>\n<pre><code class=\"typescript\">import { render, screen, within } from \"@testing-library\/react\" import userEvent from \"@testing-library\/user-event\"  import { Component } from \".\/component-with-hook\"  describe(\"Component\", () => { \u00a0 test(\"should increment count after click\", async () => { \u00a0 \u00a0 render(&lt;Component \/>)  \u00a0 \u00a0 const count = screen.getByTestId(\"count\") \u00a0 \u00a0 expect(within(count).getByText(\"0\")).toBeInTheDocument()  \u00a0 \u00a0 const button = screen.getByTestId(\"increment\") \u00a0 \u00a0 await userEvent.click(button) \u00a0 \u00a0 expect(within(count).getByText(\"1\")).toBeInTheDocument() \u00a0 }) })<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u044d\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0443\u043a\u043e\u0432, \u043d\u043e \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430?<\/p>\n<p>\u041f\u043e \u0438\u0434\u0435\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0442\u0430\u043a <code>\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 + \u043b\u043e\u0433\u0438\u043a\u0430 = \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/code><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/fc8\/7b1\/557\/fc87b15579cf06c279abd73f98c4c06a.jpg\" width=\"688\" height=\"468\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fc8\/7b1\/557\/fc87b15579cf06c279abd73f98c4c06a.jpg\" data-blurred=\"true\"\/><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a\u0430\u043a \u043d\u0430 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0447\u0430\u0441\u0442\u0435\u0439, \u0442\u043e \u0442\u0435\u0441\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u0436\u0434\u0430\u044f \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u044c (\u043b\u043e\u0433\u0438\u043a\u0430 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435) &#8212; \u044d\u0442\u043e unit.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u0445\u0443\u043a \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0414\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0445\u0443\u043a \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u044b\u0448\u0435. \u042d\u0442\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 &#8212; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0418\u043d\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 BLoC \u00abBusiness Logic Component\u00bb.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"typescript\">interface Props { \u00a0 count: number \u00a0 onIncrement?: () => void }  export const Display: React.FC&lt;Props> = ({ count, onIncrement }) => ( \u00a0 &lt;div> \u00a0 \u00a0 &lt;div> \u00a0 \u00a0 \u00a0 &lt;b>count:&lt;\/b> &lt;span data-testid=\"count\">{count}&lt;\/span> \u00a0 \u00a0 &lt;\/div> \u00a0 \u00a0 &lt;button data-testid=\"increment\" onClick={onIncrement}> \u00a0 \u00a0 \u00a0 increment \u00a0 \u00a0 &lt;\/button> \u00a0 &lt;\/div> )<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u043e\u0435\u043c \u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u043c<\/p>\n<pre><code class=\"typescript\">import { render, screen, within } from \"@testing-library\/react\" import userEvent from \"@testing-library\/user-event\"  import { Display } from \".\/display.component\"  describe(\"Display\", () => { \u00a0 test(\"should render count\", () => { \u00a0 \u00a0 render(&lt;Display count={4} \/>)  \u00a0 \u00a0 const count = screen.getByTestId(\"count\")  \u00a0 \u00a0 expect(within(count).getByText(\"4\")).toBeInTheDocument() \u00a0 })    \u00a0 test(\"should call passed callback to onIncrement prop\", async () => { \u00a0 \u00a0 const callbackMock = vi.fn() \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e vitest \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u043d\u0430\u0434 jest  \u00a0 \u00a0 render(&lt;Display count={0} onIncrement={callbackMock} \/>)  \u00a0 \u00a0 const button = screen.getByTestId(\"increment\") \u00a0 \u00a0 await userEvent.click(button) \u00a0 \u00a0 expect(callbackMock).toHaveBeenCalled() \u00a0 }) })<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0445\u0443\u043a \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c<\/p>\n<pre><code class=\"typescript\">import { useState } from \"react\"  const useCount = () => { \u00a0 const [count, setCount] = useState(0)  \u00a0 const handleIncrement = () => { \u00a0 \u00a0 setCount((c) => c + 1) \u00a0 }  \u00a0 return { value: count, increment: handleIncrement } } <\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u043c \u0445\u0443\u043a<\/p>\n<pre><code class=\"typescript\">import { renderHook, act } from \"@testing-library\/react-hooks\"  import { useCount } from \".\/count.hook\"  describe(\"hook\", () => { \u00a0 test(\"should render default value\", () => { \u00a0 \u00a0 const { result } = renderHook(() => useCount())  \u00a0 \u00a0 expect(result.current.value).toBe(0) \u00a0 })  \u00a0 test(\"should increment value\", () => { \u00a0 \u00a0 const { result } = renderHook(() => useCount())  \u00a0 \u00a0 act(() => { \u00a0 \u00a0 \u00a0 result.current.increment() \u00a0 \u00a0 })  \u00a0 \u00a0 expect(result.current.value).toBe(1) \u00a0 }) })<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0442\u043e \u0441 \u0445\u0443\u043a\u043e\u043c \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u0442\u044b\u043a\u043e\u0432\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0443 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f BLoC<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c BLoC<\/p>\n<pre><code class=\"typescript\">import { useCount } from \".\/count.hook\" import { Display } from \".\/display.component\"  const Bloc = () => { \u00a0 const count = useCount()  \u00a0 return &lt;Display count={count.value} onIncrement={count.increment} \/> }<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u043c<\/p>\n<pre><code class=\"typescript\">import { render, screen, within } from \"@testing-library\/react\"  import userEvent from \"@testing-library\/user-event\"  import { Bloc } from \".\/bloc.component\"  describe(\"Bloc\", () => { \u00a0 it(\"should increment count after click\", async () => { \u00a0 \u00a0 render(&lt;Bloc \/>)  \u00a0 \u00a0 const count = screen.getByTestId(\"count\")  \u00a0 \u00a0 expect(within(count).getByText(\"0\")).toBeInTheDocument()  \u00a0 \u00a0 const button = screen.getByTestId(\"increment\")  \u00a0 \u00a0 await userEvent.click(button)  \u00a0 \u00a0 expect(within(count).getByText(\"1\")).toBeInTheDocument() \u00a0 }) })<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f, \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u043b\u0438\u0448\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f. \u0417\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430, \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u043d\u0430. \u041d\u043e, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c, \u043d\u0430\u0448\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u043e\u0441\u043e\u0431\u043b\u0435\u043d\u0430 \u043e\u0442 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041d\u0430 \u044d\u0442\u043e \u043d\u0430\u043c \u043d\u0430\u043c\u0435\u043a\u0430\u0435\u0442 \u0445\u0443\u043a <code>renderHook<\/code> \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0443\u043a\u043e\u0432. \u0418\u043d\u0430\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043d\u0430\u0448 \u0445\u0443\u043a \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a &#171;\u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435&#187; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<blockquote>\n<p>\u041c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0445\u0443\u043a \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0430 \u0432\u043e\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438\u0437 \u0445\u0443\u043a\u0430 \u043d\u0435 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430.<\/p>\n<\/blockquote>\n<p>\u041f\u043e\u0434\u0443\u043c\u0430\u0435\u043c \u043e\u0431 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430\u0445. \u041c\u043e\u0436\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442? \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043d\u0438 \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u0430\u0441\u043f\u0435\u043a\u0442\u0435. \u0412 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u0442\u043e\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0435\u0441\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 <code>render<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/649\/762\/f70\/649762f70a72b7fdc430c3a2d26b8f39.jpg\" width=\"1080\" height=\"571\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/649\/762\/f70\/649762f70a72b7fdc430c3a2d26b8f39.jpg\" data-blurred=\"true\"\/><\/figure>\n<p>\u041c\u043e\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b HOC \u00abHigher-Order Component\u00bb &#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438\u00a0\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. HOC  \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043c\u0435\u0449\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.  C\u0430\u043c\u044b\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 &#8212; \u044d\u0442\u043e <code>connect<\/code> \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>react-redux<\/code>.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>Display<\/code>, \u0442\u043e \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0438\u0448\u044c \u043b\u043e\u0433\u0438\u043a\u0443. \u041e\u043f\u0438\u0448\u0435\u043c \u0435\u0451 \u0447\u0435\u0440\u0435\u0437 <code>@reduxjs\/toolkit<\/code>.<\/p>\n<pre><code class=\"typescript\">import { createSlice } from \"@reduxjs\/toolkit\"  export const countSlice = createSlice({ \u00a0 name: \"count\", \u00a0 initialState: { value: 0 }, \u00a0 reducers: { \u00a0 \u00a0 increment: (state) => { \u00a0 \u00a0 \u00a0 state.value += 1 \u00a0 \u00a0 }, \u00a0 }, })<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u043e\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u043c<\/p>\n<pre><code class=\"typescript\">import { countSlice } from \".\/count.slice\"  describe(\"count slice\", () => { \u00a0 it(\"should handle initial state\", () => { \u00a0 \u00a0 const actual = countSlice.reducer(undefined, { type: \"unknown\" })  \u00a0 \u00a0 expect(actual).toEqual({ value: 0 }) \u00a0 })  \u00a0 it(\"should handle increment\", () => { \u00a0 \u00a0 const actual = countSlice.reducer( \u00a0 \u00a0 \u00a0 { value: 0 }, \u00a0 \u00a0 \u00a0 countSlice.actions.increment(), \u00a0 \u00a0 ) \u00a0 \u00a0 expect(actual.value).toBe(1) \u00a0 }) })<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u044f\u043c\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u043b\u043e\u0433\u0438\u043a\u0438 \u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c. \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435.<\/p>\n<pre><code class=\"typescript\">import { connect } from \"react-redux\"  import { Display } from \".\/display.component\" import { countSlice } from \".\/count.slice\"  export const Count = connect( \u00a0 (state: { value: number }) => ({ count: state.value }), \u00a0 (dispatch) => ({ \u00a0 \u00a0 onIncrement: () => dispatch(countSlice.actions.increment()), \u00a0 }), )(Display)<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u043e\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u043c<\/p>\n<pre><code class=\"typescript\">import { render, screen, within } from \"@testing-library\/react\" import userEvent from \"@testing-library\/user-event\"  import { configureStore } from \"@reduxjs\/toolkit\"  import { Count } from \".\/count.component\" import { countSlice } from \".\/count.slice\"  const store = configureStore({ \u00a0 reducer: countSlice.reducer, })  describe(\"HOC connect\", () => { \u00a0 it(\"should increment count after click\", async () => { \u00a0 \u00a0 render(&lt;Count store={store} \/>) \/\/ \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u043e\u043f\u0441\u0430 store \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u0438\u0437 Provider \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c store  \u00a0 \u00a0 const count = screen.getByTestId(\"count\")  \u00a0 \u00a0 expect(within(count).getByText(\"0\")).toBeInTheDocument()  \u00a0 \u00a0 const button = screen.getByTestId(\"increment\")  \u00a0 \u00a0 await userEvent.click(button)  \u00a0 \u00a0 expect(within(count).getByText(\"1\")).toBeInTheDocument() \u00a0 }) })<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0437\u0430\u0432\u0435\u0442\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0443 <code>\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 + \u043b\u043e\u0433\u0438\u043a\u0430 = \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/code>. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/p>\n<p>\u041f\u043b\u044e\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u0438\u043d\u0443\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0441 \u0445\u0443\u043a\u0430\u043c\u0438 \u043d\u0435 \u0432\u0441\u0451 \u0442\u0430\u043a \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0438\u0437\u0430\u0439\u043d\u0430. \u0418 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043b\u043e\u0433\u0438\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c \u0431\u0438\u0437\u043d\u0435\u0441 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u0438\u0441\u0430\u0442\u044c \u0445\u0443\u043a \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 &#8212; \u044d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435 \u043b\u0443\u0447\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043c\u0435\u043d\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u0435 \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435. \u0425\u043e\u0442\u044f \u0435\u0441\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435.<\/p>\n<p><a href=\"https:\/\/github.com\/yaroslav-emelyanov\/hookless-approach-examples\" rel=\"noopener noreferrer nofollow\">Cc\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/784844\/\"> https:\/\/habr.com\/ru\/articles\/784844\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0425\u0443\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u043d\u0430\u043c \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439. \u041e\u043d\u0438 \u0440\u0435\u0448\u0438\u043b\u0438 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u043f\u0435\u0440\u0435\u0440\u0438\u0441\u043e\u0432\u043a\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438 \u043e\u0442\u0447\u0430\u0441\u0442\u0438 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0432 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043b\u043e\u0433\u0438\u043a\u0438. \u041f\u043e\u0447\u0435\u043c\u0443 \u0436\u0435 \u044f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043e\u0442\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u043d\u0438\u0445?<\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u0433\u0434\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0443.<\/p>\n<pre><code class=\"typescript\">import { useState } from \"react\"  const Component: React.FC = () => { \u00a0 const [count, setCount] = useState(0)  \u00a0 const handleIncrement = () => { \u00a0 \u00a0 setCount((c) => c + 1) \u00a0 }  \u00a0 return ( \u00a0 \u00a0 &lt;div> \u00a0 \u00a0 \u00a0 &lt;div data-testid=\"count\">count: {count}&lt;\/div> \u00a0 \u00a0 \u00a0 &lt;button data-testid=\"increment\" onClick={handleIncrement}>increment&lt;\/button> \u00a0 \u00a0 &lt;\/div> \u00a0 ) } <\/code><\/pre>\n<p>\u0427\u0435\u0440\u0435\u0437 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0443\u0447\u0448\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c, \u043a\u0430\u043a \u043e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u043a\u0440\u043e\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u043c \u043d\u0430\u0448\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u0435.<\/p>\n<pre><code class=\"typescript\">import { render, screen, within } from \"@testing-library\/react\" import userEvent from \"@testing-library\/user-event\"  import { Component } from \".\/component-with-hook\"  describe(\"Component\", () => { \u00a0 test(\"should increment count after click\", async () => { \u00a0 \u00a0 render(&lt;Component \/>)  \u00a0 \u00a0 const count = screen.getByTestId(\"count\") \u00a0 \u00a0 expect(within(count).getByText(\"0\")).toBeInTheDocument()  \u00a0 \u00a0 const button = screen.getByTestId(\"increment\") \u00a0 \u00a0 await userEvent.click(button) \u00a0 \u00a0 expect(within(count).getByText(\"1\")).toBeInTheDocument() \u00a0 }) })<\/code><\/pre>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u044d\u0442\u043e \u0441\u0430\u043c\u044b\u0439 \u043e\u0431\u044b\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0443\u043a\u043e\u0432, \u043d\u043e \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430?<\/p>\n<p>\u041f\u043e \u0438\u0434\u0435\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0442\u0430\u043a <code>\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 + \u043b\u043e\u0433\u0438\u043a\u0430 = \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/code><\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043a\u0430\u043a \u043d\u0430 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0447\u0430\u0441\u0442\u0435\u0439, \u0442\u043e \u0442\u0435\u0441\u0442 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043a\u0430\u0436\u0434\u0430\u044f \u0435\u0433\u043e \u0447\u0430\u0441\u0442\u044c (\u043b\u043e\u0433\u0438\u043a\u0430 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435) &#8212; \u044d\u0442\u043e unit.<\/p>\n<p>\u0414\u043b\u044f \u0434\u0435\u043a\u043e\u043c\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0432\u044b\u043d\u0435\u0441\u0435\u043c \u0432\u0441\u044e \u043b\u043e\u0433\u0438\u043a\u0443 \u0432 \u0445\u0443\u043a \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e. \u0414\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0445\u0443\u043a \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0430 \u0443\u0440\u043e\u0432\u0435\u043d\u044c \u0432\u044b\u0448\u0435. \u042d\u0442\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u044e\u0449\u0438\u0439 \u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 &#8212; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. \u0418\u043d\u043e\u0433\u0434\u0430 \u0435\u0433\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 BLoC \u00abBusiness Logic Component\u00bb.<\/p>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f<\/p>\n<pre><code class=\"typescript\">interface Props { \u00a0 count: number \u00a0 onIncrement?: () => void }  export const Display: React.FC&lt;Props> = ({ count, onIncrement }) => ( \u00a0 &lt;div> \u00a0 \u00a0 &lt;div> \u00a0 \u00a0 \u00a0 &lt;b>count:&lt;\/b> &lt;span data-testid=\"count\">{count}&lt;\/span> \u00a0 \u00a0 &lt;\/div> \u00a0 \u00a0 &lt;button data-testid=\"increment\" onClick={onIncrement}> \u00a0 \u00a0 \u00a0 increment \u00a0 \u00a0 &lt;\/button> \u00a0 &lt;\/div> )<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u043e\u0435\u043c \u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u043c<\/p>\n<pre><code class=\"typescript\">import { render, screen, within } from \"@testing-library\/react\" import userEvent from \"@testing-library\/user-event\"  import { Display } from \".\/display.component\"  describe(\"Display\", () => { \u00a0 test(\"should render count\", () => { \u00a0 \u00a0 render(&lt;Display count={4} \/>)  \u00a0 \u00a0 const count = screen.getByTestId(\"count\")  \u00a0 \u00a0 expect(within(count).getByText(\"4\")).toBeInTheDocument() \u00a0 })    \u00a0 test(\"should call passed callback to onIncrement prop\", async () => { \u00a0 \u00a0 const callbackMock = vi.fn() \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e vitest \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u043d\u0430\u0434 jest  \u00a0 \u00a0 render(&lt;Display count={0} onIncrement={callbackMock} \/>)  \u00a0 \u00a0 const button = screen.getByTestId(\"increment\") \u00a0 \u00a0 await userEvent.click(button) \u00a0 \u00a0 expect(callbackMock).toHaveBeenCalled() \u00a0 }) })<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0445\u0443\u043a \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c<\/p>\n<pre><code class=\"typescript\">import { useState } from \"react\"  const useCount = () => { \u00a0 const [count, setCount] = useState(0)  \u00a0 const handleIncrement = () => { \u00a0 \u00a0 setCount((c) => c + 1) \u00a0 }  \u00a0 return { value: count, increment: handleIncrement } } <\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u043c \u0445\u0443\u043a<\/p>\n<pre><code class=\"typescript\">import { renderHook, act } from \"@testing-library\/react-hooks\"  import { useCount } from \".\/count.hook\"  describe(\"hook\", () => { \u00a0 test(\"should render default value\", () => { \u00a0 \u00a0 const { result } = renderHook(() => useCount())  \u00a0 \u00a0 expect(result.current.value).toBe(0) \u00a0 })  \u00a0 test(\"should increment value\", () => { \u00a0 \u00a0 const { result } = renderHook(() => useCount())  \u00a0 \u00a0 act(() => { \u00a0 \u00a0 \u00a0 result.current.increment() \u00a0 \u00a0 })  \u00a0 \u00a0 expect(result.current.value).toBe(1) \u00a0 }) })<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0442\u043e \u0441 \u0445\u0443\u043a\u043e\u043c \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435\u0441\u0442\u044b\u043a\u043e\u0432\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0443 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f BLoC<\/p>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c BLoC<\/p>\n<pre><code class=\"typescript\">import { useCount } from \".\/count.hook\" import { Display } from \".\/display.component\"  const Bloc = () => { \u00a0 const count = useCount()  \u00a0 return &lt;Display count={count.value} onIncrement={count.increment} \/> }<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u043c<\/p>\n<pre><code class=\"typescript\">import { render, screen, within } from \"@testing-library\/react\"  import userEvent from \"@testing-library\/user-event\"  import { Bloc } from \".\/bloc.component\"  describe(\"Bloc\", () => { \u00a0 it(\"should increment count after click\", async () => { \u00a0 \u00a0 render(&lt;Bloc \/>)  \u00a0 \u00a0 const count = screen.getByTestId(\"count\")  \u00a0 \u00a0 expect(within(count).getByText(\"0\")).toBeInTheDocument()  \u00a0 \u00a0 const button = screen.getByTestId(\"increment\")  \u00a0 \u00a0 await userEvent.click(button)  \u00a0 \u00a0 expect(within(count).getByText(\"1\")).toBeInTheDocument() \u00a0 }) })<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0442\u0435\u0441\u0442 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f, \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f \u043b\u0438\u0448\u044c \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442.<\/p>\n<p>\u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b, \u0447\u0442\u043e \u043d\u0430 \u044d\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f. \u0417\u0430\u0434\u0430\u0447\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0430, \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0432\u043e\u0441\u0441\u043e\u0437\u0434\u0430\u043d\u0430. \u041d\u043e, \u043a\u0430\u043a \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0442\u044c, \u043d\u0430\u0448\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0431\u043e\u0441\u043e\u0431\u043b\u0435\u043d\u0430 \u043e\u0442 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041d\u0430 \u044d\u0442\u043e \u043d\u0430\u043c \u043d\u0430\u043c\u0435\u043a\u0430\u0435\u0442 \u0445\u0443\u043a <code>renderHook<\/code> \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0443\u043a\u043e\u0432. \u0418\u043d\u0430\u0447\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043d\u0430\u0448 \u0445\u0443\u043a \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a &#171;\u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0435&#187; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430.<\/p>\n<blockquote>\n<p>\u041c\u043e\u0436\u043d\u043e \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u0445\u0443\u043a \u0438\u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0430 \u0432\u043e\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438\u0437 \u0445\u0443\u043a\u0430 \u043d\u0435 \u0432\u044b\u043d\u0435\u0441\u0442\u0438 \u043d\u0438\u043a\u043e\u0433\u0434\u0430.<\/p>\n<\/blockquote>\n<p>\u041f\u043e\u0434\u0443\u043c\u0430\u0435\u043c \u043e\u0431 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u0430\u0445. \u041c\u043e\u0436\u0435\u0442 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442? \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043e\u043d\u0438 \u043d\u0435 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0432 \u044d\u0442\u043e\u043c \u0430\u0441\u043f\u0435\u043a\u0442\u0435. \u0412 \u043a\u043b\u0430\u0441\u0441\u043e\u0432\u043e\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 \u0442\u043e\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0435\u0441\u043d\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u0435\u0442\u043e\u0434 <code>render<\/code> \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u043c\u0435\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0435\u0442\u043e\u0434\u0430\u043c \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>\u041c\u043e\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0431\u044b\u043b HOC \u00abHigher-Order Component\u00bb &#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0438\u00a0\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442. HOC  \u0434\u043e\u043b\u0436\u0435\u043d \u0441\u043e\u0432\u043c\u0435\u0449\u0430\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 \u0438 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.  C\u0430\u043c\u044b\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0438\u0437 \u043d\u0438\u0445 &#8212; \u044d\u0442\u043e <code>connect<\/code> \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>react-redux<\/code>.<\/p>\n<p>\u0422\u0430\u043a \u043a\u0430\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0443\u0436\u0435 \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435, \u0432 \u0432\u0438\u0434\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 <code>Display<\/code>, \u0442\u043e \u043d\u0430\u043c \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043b\u0438\u0448\u044c \u043b\u043e\u0433\u0438\u043a\u0443. \u041e\u043f\u0438\u0448\u0435\u043c \u0435\u0451 \u0447\u0435\u0440\u0435\u0437 <code>@reduxjs\/toolkit<\/code>.<\/p>\n<pre><code class=\"typescript\">import { createSlice } from \"@reduxjs\/toolkit\"  export const countSlice = createSlice({ \u00a0 name: \"count\", \u00a0 initialState: { value: 0 }, \u00a0 reducers: { \u00a0 \u00a0 increment: (state) => { \u00a0 \u00a0 \u00a0 state.value += 1 \u00a0 \u00a0 }, \u00a0 }, })<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u043e\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u043c<\/p>\n<pre><code class=\"typescript\">import { countSlice } from \".\/count.slice\"  describe(\"count slice\", () => { \u00a0 it(\"should handle initial state\", () => { \u00a0 \u00a0 const actual = countSlice.reducer(undefined, { type: \"unknown\" })  \u00a0 \u00a0 expect(actual).toEqual({ value: 0 }) \u00a0 })  \u00a0 it(\"should handle increment\", () => { \u00a0 \u00a0 const actual = countSlice.reducer( \u00a0 \u00a0 \u00a0 { value: 0 }, \u00a0 \u00a0 \u00a0 countSlice.actions.increment(), \u00a0 \u00a0 ) \u00a0 \u00a0 expect(actual.value).toBe(1) \u00a0 }) })<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435, \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u044f\u043c\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u043b\u043e\u0433\u0438\u043a\u0438 \u0441 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c. \u041f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u043e\u0434\u043d\u043e \u0446\u0435\u043b\u043e\u0435.<\/p>\n<pre><code class=\"typescript\">import { connect } from \"react-redux\"  import { Display } from \".\/display.component\" import { countSlice } from \".\/count.slice\"  export const Count = connect( \u00a0 (state: { value: number }) => ({ count: state.value }), \u00a0 (dispatch) => ({ \u00a0 \u00a0 onIncrement: () => dispatch(countSlice.actions.increment()), \u00a0 }), )(Display)<\/code><\/pre>\n<p>\u041f\u043e\u043a\u0440\u043e\u0435\u043c \u0442\u0435\u0441\u0442\u043e\u043c<\/p>\n<pre><code class=\"typescript\">import { render, screen, within } from \"@testing-library\/react\" import userEvent from \"@testing-library\/user-event\"  import { configureStore } from \"@reduxjs\/toolkit\"  import { Count } from \".\/count.component\" import { countSlice } from \".\/count.slice\"  const store = configureStore({ \u00a0 reducer: countSlice.reducer, })  describe(\"HOC connect\", () => { \u00a0 it(\"should increment count after click\", async () => { \u00a0 \u00a0 render(&lt;Count store={store} \/>) \/\/ \u0412\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u043e\u043f\u0441\u0430 store \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u0438\u0437 Provider \u0441 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u043c store  \u00a0 \u00a0 const count = screen.getByTestId(\"count\")  \u00a0 \u00a0 expect(within(count).getByText(\"0\")).toBeInTheDocument()  \u00a0 \u00a0 const button = screen.getByTestId(\"increment\")  \u00a0 \u00a0 await userEvent.click(button)  \u00a0 \u00a0 expect(within(count).getByText(\"1\")).toBeInTheDocument() \u00a0 }) })<\/code><\/pre>\n<p>\u041c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0437\u0430\u0432\u0435\u0442\u043d\u0443\u044e \u0444\u043e\u0440\u043c\u0443\u043b\u0443 <code>\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 + \u043b\u043e\u0433\u0438\u043a\u0430 = \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/code>. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043b\u044e\u0441\u044b \u0438 \u043c\u0438\u043d\u0443\u0441\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0430.<\/p>\n<p>\u041f\u043b\u044e\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u0435 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0423\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u0438\u043d\u0443\u0441\u044b:<\/p>\n<ul>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/p>\n<\/li>\n<li>\n<p>\u0423\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u043e\u0432\u043e\u0439 \u0431\u0430\u0437\u044b<\/p>\n<\/li>\n<li>\n<p>\u0423\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043c\u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u0435, \u0447\u0442\u043e \u0441 \u0445\u0443\u043a\u0430\u043c\u0438 \u043d\u0435 \u0432\u0441\u0451 \u0442\u0430\u043a \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0438\u0437\u0430\u0439\u043d\u0430. \u0418 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u043b\u043e\u0433\u0438\u043a\u0430 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c \u0431\u0438\u0437\u043d\u0435\u0441 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f. \u041f\u0438\u0441\u0430\u0442\u044c \u0445\u0443\u043a \u0432 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0435 &#8212; \u044d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043d\u0435 \u043b\u0443\u0447\u0448\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u043d\u043e \u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b, \u043c\u0435\u043d\u0435\u0435 \u0433\u0438\u0431\u043a\u0438\u0435 \u0438 \u043f\u0440\u043e\u0441\u0442\u044b\u0435. \u0425\u043e\u0442\u044f \u0435\u0441\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e \u0434\u0430\u043d\u043d\u043e\u0439 \u0442\u0435\u043c\u0435.<\/p>\n<p><a href=\"https:\/\/github.com\/yaroslav-emelyanov\/hookless-approach-examples\" rel=\"noopener noreferrer nofollow\">Cc\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \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\/articles\/784844\/\"> https:\/\/habr.com\/ru\/articles\/784844\/<\/a><br \/><\/br><\/br><\/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-364666","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/364666","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=364666"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/364666\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=364666"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=364666"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=364666"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}