{"id":95420,"date":"2025-01-31T16:20:04","date_gmt":"2025-01-31T12:50:04","guid":{"rendered":"https:\/\/nabfollower.com\/blog\/5-%d9%82%d9%84%d8%a7%d8%a8-%d8%b3%d9%81%d8%a7%d8%b1%d8%b4%db%8c-%d8%a8%d8%b1%d8%aa%d8%b1-%d8%a8%d8%b1%d8%a7%db%8c-react\/"},"modified":"2025-01-31T16:20:04","modified_gmt":"2025-01-31T12:50:04","slug":"5-%d9%82%d9%84%d8%a7%d8%a8-%d8%b3%d9%81%d8%a7%d8%b1%d8%b4%db%8c-%d8%a8%d8%b1%d8%aa%d8%b1-%d8%a8%d8%b1%d8%a7%db%8c-react","status":"publish","type":"post","link":"https:\/\/nabfollower.com\/blog\/5-%d9%82%d9%84%d8%a7%d8%a8-%d8%b3%d9%81%d8%a7%d8%b1%d8%b4%db%8c-%d8%a8%d8%b1%d8%aa%d8%b1-%d8%a8%d8%b1%d8%a7%db%8c-react\/","title":{"rendered":"5 \u0642\u0644\u0627\u0628 \u0633\u0641\u0627\u0631\u0634\u06cc \u0628\u0631\u062a\u0631 \u0628\u0631\u0627\u06cc React"},"content":{"rendered":"<div data-article-id=\"2252213\" id=\"article-body\">\n<p>\u0633\u0644\u0627\u0645 \u0628\u0647 \u0647\u0645\u0647 Slao \u0627\u0633\u062a \u060c <br \/>\u0645\u0648\u0627\u0631\u062f \u0632\u06cc\u0631 5 \u0642\u0644\u0627\u0628 \u0628\u0631\u062a\u0631 \u0645\u0646\u0627\u0633\u0628 \u0648 \u062c\u062f\u06cc\u062f \u0628\u0631\u0627\u06cc \u0647\u0645\u0647 \u062e\u0648\u0627\u0647\u062f \u0628\u0648\u062f \u06a9\u0647 \u0647\u0645\u0647 \u0628\u062a\u0648\u0627\u0646\u0646\u062f \u0627\u0632 \u0622\u0646 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u0646\u062f <\/p>\n<p><strong>usemediaquery<\/strong><\/p>\n<p>Usemediaquery \u0628\u0647 \u0646\u0645\u0627\u06cc\u0634 \u062f\u0627\u062f\u0647 \u0647\u0627\u06cc \u0631\u0633\u0627\u0646\u0647 \u0627\u06cc \u06af\u0648\u0634 \u0645\u06cc \u062f\u0647\u062f \u0648 \u0628\u0647 \u0634\u0645\u0627 \u0627\u0645\u06a9\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f \u0627\u0646\u0648\u0627\u0639 \u06cc\u0627 \u0631\u0641\u062a\u0627\u0631\u0647\u0627\u06cc \u062e\u0627\u0635\u06cc \u0631\u0627 \u0628\u0631 \u0627\u0633\u0627\u0633 \u0627\u0646\u062f\u0627\u0632\u0647 \u062a\u062c\u0647\u06cc\u0632\u0627\u062a \u0627\u0639\u0645\u0627\u0644 \u06a9\u0646\u06cc\u062f<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>import { useEffect, useState } from 'react';\n\nfunction useMediaQuery(query) {\n  const [matches, setMatches] = useState(false);\n\n  useEffect(() =&gt; {\n    const mediaQuery = window.matchMedia(query);\n    setMatches(mediaQuery.matches);\n\n    const handler = event =&gt; setMatches(event.matches);\n    mediaQuery.addEventListener('change', handler);\n\n    return () =&gt; mediaQuery.removeEventListener('change', handler);\n  }, [query]);\n\n  return matches;\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f\u0646<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>const isLargeScreen = useMediaQuery('(min-width: 1024px)');\n\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u0627\u0633\u062a\u0641\u0627\u062f\u0647<\/strong><\/p>\n<p>HOOK CEASEWEBECKETE \u0628\u0631\u0646\u0627\u0645\u0647 \u0634\u0645\u0627 \u0631\u0627 \u0628\u0647 \u0633\u0631\u0648\u0631 WebSocket \u0645\u062a\u0635\u0644 \u0645\u06cc \u06a9\u0646\u062f \u0648 \u0628\u0647 \u0631\u0627\u062d\u062a\u06cc \u062f\u0627\u062f\u0647 \u0647\u0627\u06cc \u0632\u0645\u0627\u0646 \u0648\u0627\u0642\u0639\u06cc \u0631\u0627 \u0627\u0631\u0633\u0627\u0644 \u0648 \u062f\u0631\u06cc\u0627\u0641\u062a \u0645\u06cc \u06a9\u0646\u062f. \u0627\u06cc\u0646 \u0627\u062a\u0635\u0627\u0644\u0627\u062a \u060c \u0628\u0627\u0641\u0631 \u067e\u06cc\u0627\u0645 \u0648 \u0631\u0633\u06cc\u062f\u06af\u06cc \u0628\u0647 \u0631\u0648\u06cc\u062f\u0627\u062f\u0647\u0627 \u0631\u0627 \u067e\u0631\u062f\u0627\u0632\u0634 \u0645\u06cc \u06a9\u0646\u062f \u0648 \u0628\u0647 \u0631\u0648\u0632\u0631\u0633\u0627\u0646\u06cc \u0622\u0646 \u0622\u0633\u0627\u0646 \u0627\u0633\u062a<\/p>\n<p>\u0627\u06cc\u0646 \u0645\u062b\u0627\u0644 \u06cc\u06a9 Webocket Hook \u0631\u0627 \u0627\u0631\u0627\u0626\u0647 \u0645\u06cc \u062f\u0647\u062f \u06a9\u0647 \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u0628\u0627 \u0645\u062f\u06cc\u0631\u06cc\u062a \u0627\u062a\u0635\u0627\u0644 \u060c \u067e\u0631\u062f\u0627\u0632\u0634 \u0631\u0648\u06cc\u062f\u0627\u062f\u0647\u0627 \u0648 \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc \u062a\u0645\u06cc\u0632 \u06a9\u0646\u0646\u062f\u0647 \u0628\u0647 \u0637\u0648\u0631 \u0645\u0631\u062a\u0628 \u0645\u0648\u0631\u062f \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0642\u0631\u0627\u0631 \u06af\u06cc\u0631\u062f.<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>import { useState, useEffect, useRef, useCallback } from 'react';\n\nfunction useWebSocket(url, options = {}) {\n  const { reconnect = true, reconnectInterval = 5000, onOpen, onMessage, onError, onClose } = options;\n  const [isConnected, setIsConnected] = useState(false);\n  const [lastMessage, setLastMessage] = useState(null);\n  const websocketRef = useRef(null);\n  const reconnectTimeout = useRef(null);\n\n  const connect = useCallback(() =&gt; {\n    websocketRef.current = new WebSocket(url);\n\n    websocketRef.current.onopen = (event) =&gt; {\n      setIsConnected(true);\n      onOpen &amp;&amp; onOpen(event);\n    };\n\n    websocketRef.current.onmessage = (event) =&gt; {\n      setLastMessage(event.data);\n      onMessage &amp;&amp; onMessage(event);\n    };\n\n    websocketRef.current.onerror = (event) =&gt; {\n      onError &amp;&amp; onError(event);\n    };\n\n    websocketRef.current.onclose = (event) =&gt; {\n      setIsConnected(false);\n      onClose &amp;&amp; onClose(event);\n      if (reconnect) {\n        reconnectTimeout.current = setTimeout(connect, reconnectInterval);\n      }\n    };\n  }, [url, reconnect, reconnectInterval, onOpen, onMessage, onError, onClose]);\n\n  const sendMessage = useCallback((message) =&gt; {\n    if (isConnected &amp;&amp; websocketRef.current) {\n      websocketRef.current.send(message);\n    }\n  }, [isConnected]);\n\n  useEffect(() =&gt; {\n    connect();\n\n    return () =&gt; {\n      if (websocketRef.current) {\n        websocketRef.current.close();\n      }\n      clearTimeout(reconnectTimeout.current);\n    };\n  }, [connect]);\n\n  return { isConnected, sendMessage, lastMessage };\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p>\u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc UseWebocket<\/p>\n<ul>\n<li>\u0627\u0646\u062a\u0642\u0627\u0644 \u0645\u062c\u062f\u062f: \u0627\u06af\u0631 \u0627\u062a\u0635\u0627\u0644 \u0628\u0633\u062a\u0647 \u0634\u0648\u062f \u060c \u067e\u0633 \u0627\u0632 \u0645\u062f\u062a \u0632\u0645\u0627\u0646 \u0645\u0634\u062e\u0635\u06cc \u0628\u0647 \u0637\u0648\u0631 \u062e\u0648\u062f\u06a9\u0627\u0631 \u062f\u0648\u0628\u0627\u0631\u0647 \u0648\u0635\u0644 \u0645\u06cc \u0634\u0648\u062f<\/li>\n<li>\u0631\u0633\u06cc\u062f\u06af\u06cc \u0628\u0647 \u0631\u0648\u06cc\u062f\u0627\u062f: \u0648\u06cc\u0698\u06af\u06cc \u0647\u0627\u06cc\u06cc \u0631\u0627 \u0628\u0631\u0627\u06cc \u062a\u0645\u0627\u0633 \u0628\u0627 Onopen \u060c OnMessage \u060c OnError \u0648 Onclose \u0642\u0628\u0648\u0644 \u06a9\u0646\u06cc\u062f \u062a\u0627 \u062f\u0631 \u0635\u0648\u0631\u062a \u0644\u0632\u0648\u0645 \u0631\u0633\u06cc\u062f\u06af\u06cc \u06a9\u0646\u06cc\u062f<\/li>\n<li>\u0627\u0631\u0633\u0627\u0644 \u067e\u06cc\u0627\u0645: \u0627\u0646\u0631\u0698\u06cc SendMessage \u0631\u0627 \u0641\u0631\u0627\u0647\u0645 \u0645\u06cc \u06a9\u0646\u062f \u06a9\u0647 \u0641\u0642\u0637 \u0647\u0646\u06af\u0627\u0645 \u0628\u0627\u0632 \u0634\u062f\u0646 WebSocket \u067e\u06cc\u0627\u0645 \u0631\u0627 \u0627\u0631\u0633\u0627\u0644 \u0645\u06cc \u06a9\u0646\u062f<\/li>\n<li>\u0622\u062e\u0631\u06cc\u0646 \u0630\u062e\u06cc\u0631\u0647 \u067e\u06cc\u0627\u0645: \u0622\u062e\u0631\u06cc\u0646 \u062f\u0627\u062f\u0647 \u0647\u0627\u06cc \u062f\u0631\u06cc\u0627\u0641\u062a \u0634\u062f\u0647 \u0631\u0627 \u0630\u062e\u06cc\u0631\u0647 \u06a9\u0646\u06cc\u062f \u060c \u0646\u0632\u062f\u06cc\u06a9\u062a\u0631\u06cc\u0646 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0631\u0627 \u0628\u062f\u0648\u0646 \u062b\u0628\u062a \u0646\u0627\u0645 \u0628\u067e\u0630\u06cc\u0631\u06cc\u062f.<\/li>\n<\/ul>\n<p>\u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0631\u062f\u0646<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>function ChatApp() {\n  const { isConnected, sendMessage, lastMessage } = useWebSocket('ws:\/\/localhost:4000\/chat', {\n    reconnect: true,\n    reconnectInterval: 3000,\n    onOpen: () =&gt; console.log('Connected to WebSocket'),\n    onMessage: (event) =&gt; console.log('New message received:', event.data),\n    onClose: () =&gt; console.log('Disconnected from WebSocket'),\n  });\n\n  const [inputValue, setInputValue] = useState('');\n\n  const handleSend = () =&gt; {\n    sendMessage(inputValue);\n    setInputValue('');\n  };\n\n  return (\n    <div>\n      <div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter-rtl ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">\u0641\u0647\u0631\u0633\u062a \u0645\u0637\u0627\u0644\u0628<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/nabfollower.com\/blog\/5-%d9%82%d9%84%d8%a7%d8%a8-%d8%b3%d9%81%d8%a7%d8%b1%d8%b4%db%8c-%d8%a8%d8%b1%d8%aa%d8%b1-%d8%a8%d8%b1%d8%a7%db%8c-react\/#WebSocket_Chat\" >WebSocket Chat<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/nabfollower.com\/blog\/5-%d9%82%d9%84%d8%a7%d8%a8-%d8%b3%d9%81%d8%a7%d8%b1%d8%b4%db%8c-%d8%a8%d8%b1%d8%aa%d8%b1-%d8%a8%d8%b1%d8%a7%db%8c-react\/#Last_Message\" >Last Message:<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"WebSocket_Chat\"><\/span>WebSocket Chat<span class=\"ez-toc-section-end\"><\/span><\/h3>\n      \n      <div>\n        <h4><span class=\"ez-toc-section\" id=\"Last_Message\"><\/span>Last Message:<span class=\"ez-toc-section-end\"><\/span><\/h4>\n        <p>{lastMessage}<\/p>\n      <\/div>\n    <\/div>\n  );\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u0627\u0631\u0628\u0627\u0628<\/strong><\/p>\n<p>\u0634\u0646\u0627\u0633\u0627\u06cc\u06cc \u0645\u0627\u0648\u0633 \u0627\u0632 \u0637\u0631\u06cc\u0642 \u06cc\u06a9 \u0639\u0646\u0635\u0631 \u0628\u0631\u0627\u06cc \u0631\u0633\u06cc\u062f\u06af\u06cc \u0628\u0647 \u0627\u0628\u0632\u0627\u0631\u0647\u0627 \u060c \u0627\u0646\u06cc\u0645\u06cc\u0634\u0646 \u0647\u0627 \u06cc\u0627 \u0647\u0631 \u0628\u0627\u0632\u062e\u0648\u0631\u062f UI \u062f\u0631 \u0645\u0648\u0631\u062f \u0645\u0627\u0648\u0633<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>import { useState, useRef, useEffect } from 'react';\n\nfunction useHover() {\n  const [hovered, setHovered] = useState(false);\n  const ref = useRef(null);\n\n  useEffect(() =&gt; {\n    const handleMouseOver = () =&gt; setHovered(true);\n    const handleMouseOut = () =&gt; setHovered(false);\n    const node = ref.current;\n    if (node) {\n      node.addEventListener('mouseover', handleMouseOver);\n      node.addEventListener('mouseout', handleMouseOut);\n    }\n    return () =&gt; {\n      if (node) {\n        node.removeEventListener('mouseover', handleMouseOver);\n        node.removeEventListener('mouseout', handleMouseOut);\n      }\n    };\n  }, [ref]);\n\n  return [ref, hovered];\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>const [hoverRef, isHovered] = useHover();\n\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>\u062f\u0631 \u062d\u0627\u0644\u06cc \u06a9\u0647 \u062f\u0631 Debounce<\/strong><\/p>\n<p>\u062c\u0644\u0648\u06af\u06cc\u0631\u06cc \u0627\u0632 \u0641\u0639\u0627\u0644 \u0634\u062f\u0646 \u0633\u0631\u06cc\u0639 \u0648\u0642\u0627\u06cc\u0639 \u060c \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u0634\u062f\u0647 \u0645\u0645\u06a9\u0646 \u0627\u0633\u062a \u0628\u0631\u0627\u06cc \u0632\u0645\u06cc\u0646\u0647 \u0647\u0627\u06cc \u0648\u0631\u0648\u062f\u06cc \u06cc\u0627 \u0645\u06cc\u0644\u0647 \u0647\u0627\u06cc \u062c\u0633\u062a\u062c\u0648 \u0645\u0641\u06cc\u062f \u0628\u0627\u0634\u062f<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>import { useState, useEffect } from 'react';\n\nfunction useDebounce(value, delay) {\n  const [debouncedValue, setDebouncedValue] = useState(value);\n\n  useEffect(() =&gt; {\n    const handler = setTimeout(() =&gt; {\n      setDebouncedValue(value);\n    }, delay);\n\n    return () =&gt; clearTimeout(handler);\n  }, [value, delay]);\n\n  return debouncedValue;\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>const debouncedSearchTerm = useDebounce(searchTerm, 500);\n\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><strong>useInfinitesCroll<\/strong><\/p>\n<p>Hook UseInfinitesCroll \u0628\u0631\u0627\u06cc \u06cc\u0627\u0641\u062a\u0646 \u062f\u0627\u062f\u0647 \u0647\u0627 \u0647\u0646\u06af\u0627\u0645 \u067e\u0627\u06cc\u06cc\u0646 \u0622\u0645\u062f\u0646 \u06a9\u0627\u0631\u0628\u0631\u0627\u0646 \u0628\u0633\u06cc\u0627\u0631 \u0645\u0641\u06cc\u062f \u0627\u0633\u062a. \u0627\u06cc\u0646 \u0645\u06cc \u062a\u0648\u0627\u0646\u062f \u0628\u0631\u06a9\u0627\u062a\u06cc \u0645\u0627\u0646\u0646\u062f \u0628\u0627\u0631\u06af\u06cc\u0631\u06cc \u060c \u0631\u0633\u06cc\u062f\u06af\u06cc \u0628\u0647 \u062e\u0637\u0627 \u060c \u0635\u0641\u062d\u0647 \u0628\u0646\u062f\u06cc \u0631\u0627 \u062a\u062d\u0645\u0644 \u06a9\u0646\u062f &#8230;<\/p>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>import { useState, useEffect, useRef, useCallback } from 'react';\n\nfunction useInfiniteScroll(fetchData, options = {}) {\n  const { threshold = 0.8, hasMore = true } = options;\n  const [data, setData] = useState([]);\n  const [loading, setLoading] = useState(false);\n  const [error, setError] = useState(null);\n  const observerRef = useRef();\n\n  const loadMore = useCallback(async () =&gt; {\n    if (loading || !hasMore) return;\n    setLoading(true);\n    setError(null);\n    try {\n      const newData = await fetchData();\n      setData((prevData) =&gt; [...prevData, ...newData]);\n    } catch (err) {\n      setError(err);\n    } finally {\n      setLoading(false);\n    }\n  }, [fetchData, loading, hasMore]);\n\n  useEffect(() =&gt; {\n    if (!hasMore) return;\n\n    const observer = new IntersectionObserver(\n      (entries) =&gt; {\n        if (entries[0].isIntersecting) {\n          loadMore();\n        }\n      },\n      { threshold }\n    );\n\n    if (observerRef.current) observer.observe(observerRef.current);\n\n    return () =&gt; {\n      if (observerRef.current) observer.unobserve(observerRef.current);\n    };\n  }, [loadMore, hasMore, threshold]);\n\n  return { data, loading, error, observerRef };\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"highlight js-code-highlight\">\n<pre class=\"highlight plaintext\"><code>function InfiniteScrollList() {\n  const fetchMoreData = async () =&gt; {\n    const response = await fetch('\/api\/data'); \/\/ Example API\n    return response.json();\n  };\n\n  const { data, loading, error, observerRef } = useInfiniteScroll(fetchMoreData, {\n    threshold: 0.9,\n    hasMore: true\n  });\n\n  return (\n    <div>\n      {data.map((item, index) =&gt; (\n        <p>{item}<\/p>\n      ))}\n      \n      {loading &amp;&amp; <p>Loading...<\/p>}\n      {error &amp;&amp; <p>Error loading data...<\/p>}\n    <\/div>\n  );\n}\n<\/code><\/pre>\n<div class=\"highlight__panel js-actions-panel\">\n<div class=\"highlight__panel-action js-fullscreen-code-action\">\n    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-on\"><title>\u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u0631\u0627 \u0648\u0627\u0631\u062f \u06a9\u0646\u06cc\u062f<\/title>\n    <path d=\"M16 3h6v6h-2V5h-4V3zM2 3h6v2H4v4H2V3zm18 16v-4h2v6h-6v-2h4zM4 19h4v2H2v-6h2v4z\"\/>\n<\/svg><\/p>\n<p>    <svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" class=\"highlight-action crayons-icon highlight-action--fullscreen-off\"><title>\u0627\u0632 \u062d\u0627\u0644\u062a \u062a\u0645\u0627\u0645 \u0635\u0641\u062d\u0647 \u062e\u0627\u0631\u062c \u0634\u0648\u06cc\u062f<\/title>\n    <path d=\"M18 7h4v2h-6V3h2v4zM8 9H2V7h4V3h2v6zm10 8v4h-2v-6h6v2h-4zM8 15v6H6v-4H2v-2h6z\"\/>\n<\/svg><\/p>\n<\/div>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u0633\u0644\u0627\u0645 \u0628\u0647 \u0647\u0645\u0647 Slao \u0627\u0633\u062a \u060c \u0645\u0648\u0627\u0631\u062f \u0632\u06cc\u0631 5 \u0642\u0644\u0627\u0628 \u0628\u0631\u062a\u0631 \u0645\u0646\u0627\u0633\u0628 \u0648 \u062c\u062f\u06cc\u062f \u0628\u0631\u0627\u06cc \u0647\u0645\u0647 \u062e\u0648\u0627\u0647\u062f \u0628\u0648\u062f \u06a9\u0647 \u0647\u0645\u0647 \u0628\u062a\u0648\u0627\u0646\u0646\u062f \u0627\u0632 \u0622\u0646 \u0627\u0633\u062a\u0641\u0627\u062f\u0647 \u06a9\u0646\u0646\u062f usemediaquery Usemediaquery \u0628\u0647 \u0646\u0645\u0627\u06cc\u0634 \u062f\u0627\u062f\u0647 \u0647\u0627\u06cc \u0631\u0633\u0627\u0646\u0647 \u0627\u06cc \u06af\u0648\u0634 \u0645\u06cc \u062f\u0647\u062f \u0648 \u0628\u0647 \u0634\u0645\u0627 \u0627\u0645\u06a9\u0627\u0646 \u0645\u06cc \u062f\u0647\u062f \u0627\u0646\u0648\u0627\u0639 \u06cc\u0627 \u0631\u0641\u062a\u0627\u0631\u0647\u0627\u06cc \u062e\u0627\u0635\u06cc \u0631\u0627 \u0628\u0631 \u0627\u0633\u0627\u0633 \u0627\u0646\u062f\u0627\u0632\u0647 \u062a\u062c\u0647\u06cc\u0632\u0627\u062a \u0627\u0639\u0645\u0627\u0644 \u06a9\u0646\u06cc\u062f import { &hellip;<\/p>\n","protected":false},"author":2,"featured_media":95421,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/media2.dev.to\/dynamic\/image\/width=1000,height=500,fit=cover,gravity=auto,format=auto\/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4sn9xpjsedqr10dgla4g.png","fifu_image_alt":"","footnotes":""},"categories":[339],"tags":[],"class_list":["post-95420","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev"],"_links":{"self":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/95420","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/comments?post=95420"}],"version-history":[{"count":0,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/posts\/95420\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media\/95421"}],"wp:attachment":[{"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/media?parent=95420"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/categories?post=95420"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nabfollower.com\/blog\/wp-json\/wp\/v2\/tags?post=95420"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}