{"id":9347,"date":"2025-08-29T19:41:39","date_gmt":"2025-08-29T14:11:39","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=9347"},"modified":"2025-08-29T20:16:10","modified_gmt":"2025-08-29T14:46:10","slug":"beginners-guide-to-react-hooks","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/","title":{"rendered":"Beginners guide to react hooks"},"content":{"rendered":"\n<p>When you start learning front-end you\u2019ll hear a lot about JavaScript libraries especially react  so What is  exactly React?<\/p>\n\n\n\n<p>React is a JavaScript library created by Facebook by the help of which we can build fast interactive reusable user interfaces<\/p>\n\n\n\n<p>why is react so popular ?<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>we can reuse components<\/li>\n\n\n\n<li>its fast<\/li>\n\n\n\n<li>good community support<\/li>\n\n\n\n<li>largerly used in many companies<\/li>\n<\/ol>\n\n\n\n<p>today lets talk about react components<\/p>\n\n\n\n<p>1.useState \u2013 managing state<br>2.useEffect \u2013 side effects (API calls, timers, etc.)<br>3.useRef \u2013 referencing DOM elements<br>4.useContext \u2013 global state sharing<br>Custom hooks (reusable logic)<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>useState:<\/strong> It allows you to add state (data that changes) inside a function<\/li>\n<\/ol>\n\n\n\n<p>import React, { useState } from &#8220;react&#8221;;<\/p>\n\n\n\n<p>function Counter() {<br>const [count, setCount] = useState(0); \/\/ initial value = 0<\/p>\n\n\n\n<p>return (<\/p>\n\n\n\n<p>Count: {count}<\/p>\n\n\n\n<p>setCount(count + 1)}&gt;Increment<br>);<br>}<\/p>\n\n\n\n<p>export default Counter;<\/p>\n\n\n\n<p>2.  <strong>useEffect<\/strong> \u2013 Handle Side Effects<\/p>\n\n\n\n<p>Think of this as code that should run when something happens (like fetching data, updating the DOM, or running on mount).<\/p>\n\n\n\n<p>import React, { useState, useEffect } from &#8220;react&#8221;;<\/p>\n\n\n\n<p>function Timer() {<br>const [seconds, setSeconds] = useState(0);<\/p>\n\n\n\n<p>useEffect(() =&gt; {<br>const interval = setInterval(() =&gt; {<br>setSeconds((prev) =&gt; prev + 1);<br>}, 1000);<\/p>\n\n\n\n<p>}, []);<\/p>\n\n\n\n<p>return () =&gt; clearInterval(interval); \/\/ cleanup<\/p>\n\n\n\n<p>return<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Time: {seconds}s<\/h5>\n\n\n\n<p>;<br>}<\/p>\n\n\n\n<p>export default Timer;<\/p>\n\n\n\n<p>3.<strong>useContext<\/strong> \u2013 Share Data Easily<\/p>\n\n\n\n<p>Passing props through multiple levels of components can be messy. With <code>useContext<\/code>, you can <strong>share global state<\/strong> across your app without prop drilling.<\/p>\n\n\n\n<p>Example use case: Sharing a theme (dark\/light) or user authentication status<\/p>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li><strong>useRef <\/strong>\u2013 Store Values Without Re-rendering<\/li>\n<\/ol>\n\n\n\n<p>The <code>useRef<\/code> hook is used to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Directly access DOM elements<\/li>\n\n\n\n<li>Store values between renders without causing re-renders<\/li>\n<\/ul>\n\n\n\n<p>Example: focusing an input field automatically.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When you start learning front-end you\u2019ll hear a lot about JavaScript libraries especially react so What is exactly React? React is a JavaScript library created by Facebook by the help of which we can build fast interactive reusable user interfaces why is react so popular ? today lets talk about&hellip; <a href=\"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/\" class=\"more-link read-more\" rel=\"bookmark\">Continue Reading <span class=\"screen-reader-text\">Beginners guide to react hooks<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":527,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-9347","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-uncategorized","7":"h-entry","9":"h-as-article"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pheonix Solutions - We Empower Your Business Growth<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pheonix Solutions - We Empower Your Business Growth\" \/>\n<meta property=\"og:description\" content=\"When you start learning front-end you\u2019ll hear a lot about JavaScript libraries especially react so What is exactly React? React is a JavaScript library created by Facebook by the help of which we can build fast interactive reusable user interfaces why is react so popular ? today lets talk about&hellip; Continue Reading Beginners guide to react hooks\" \/>\n<meta property=\"og:url\" content=\"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/\" \/>\n<meta property=\"og:site_name\" content=\"PHEONIXSOLUTIONS\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/PheonixSolutions-209942982759387\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-29T14:11:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-29T14:46:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2016\/09\/PX2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"3837\" \/>\n\t<meta property=\"og:image:height\" content=\"2540\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"kedar p\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pheonixsolution\" \/>\n<meta name=\"twitter:site\" content=\"@pheonixsolution\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kedar p\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/\"},\"author\":{\"name\":\"kedar p\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/4e85fd49b9effeb3f8d20a4751749d87\"},\"headline\":\"Beginners guide to react hooks\",\"datePublished\":\"2025-08-29T14:11:39+00:00\",\"dateModified\":\"2025-08-29T14:46:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/\"},\"wordCount\":252,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/\",\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/\",\"name\":\"Pheonix Solutions - We Empower Your Business Growth\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2025-08-29T14:11:39+00:00\",\"dateModified\":\"2025-08-29T14:46:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/beginners-guide-to-react-hooks\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Beginners guide to react hooks\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/\",\"name\":\"Pheonix Solutions\",\"description\":\"We Empower Your Business Growth\",\"publisher\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#organization\",\"name\":\"PheonixSolutions\",\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/logo.png\",\"contentUrl\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2016\\\/12\\\/logo.png\",\"width\":454,\"height\":300,\"caption\":\"PheonixSolutions\"},\"image\":{\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/PheonixSolutions-209942982759387\\\/\",\"https:\\\/\\\/x.com\\\/pheonixsolution\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/4e85fd49b9effeb3f8d20a4751749d87\",\"name\":\"kedar p\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3c6a6152b6071b941fa46f5d58caddbf062e588f9a18d0df11ecdea42e964097?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3c6a6152b6071b941fa46f5d58caddbf062e588f9a18d0df11ecdea42e964097?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3c6a6152b6071b941fa46f5d58caddbf062e588f9a18d0df11ecdea42e964097?s=96&r=g\",\"caption\":\"kedar p\"},\"url\":\"https:\\\/\\\/pheonixsolutions.com\\\/blog\\\/author\\\/kedar\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pheonix Solutions - We Empower Your Business Growth","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/","og_locale":"en_US","og_type":"article","og_title":"Pheonix Solutions - We Empower Your Business Growth","og_description":"When you start learning front-end you\u2019ll hear a lot about JavaScript libraries especially react so What is exactly React? React is a JavaScript library created by Facebook by the help of which we can build fast interactive reusable user interfaces why is react so popular ? today lets talk about&hellip; Continue Reading Beginners guide to react hooks","og_url":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/","og_site_name":"PHEONIXSOLUTIONS","article_publisher":"https:\/\/www.facebook.com\/PheonixSolutions-209942982759387\/","article_published_time":"2025-08-29T14:11:39+00:00","article_modified_time":"2025-08-29T14:46:10+00:00","og_image":[{"width":3837,"height":2540,"url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2016\/09\/PX2.png","type":"image\/png"}],"author":"kedar p","twitter_card":"summary_large_image","twitter_creator":"@pheonixsolution","twitter_site":"@pheonixsolution","twitter_misc":{"Written by":"kedar p","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/#article","isPartOf":{"@id":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/"},"author":{"name":"kedar p","@id":"https:\/\/pheonixsolutions.com\/blog\/#\/schema\/person\/4e85fd49b9effeb3f8d20a4751749d87"},"headline":"Beginners guide to react hooks","datePublished":"2025-08-29T14:11:39+00:00","dateModified":"2025-08-29T14:46:10+00:00","mainEntityOfPage":{"@id":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/"},"wordCount":252,"commentCount":0,"publisher":{"@id":"https:\/\/pheonixsolutions.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/","url":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/","name":"Pheonix Solutions - We Empower Your Business Growth","isPartOf":{"@id":"https:\/\/pheonixsolutions.com\/blog\/#website"},"datePublished":"2025-08-29T14:11:39+00:00","dateModified":"2025-08-29T14:46:10+00:00","breadcrumb":{"@id":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/pheonixsolutions.com\/blog\/beginners-guide-to-react-hooks\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/pheonixsolutions.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Beginners guide to react hooks"}]},{"@type":"WebSite","@id":"https:\/\/pheonixsolutions.com\/blog\/#website","url":"https:\/\/pheonixsolutions.com\/blog\/","name":"Pheonix Solutions","description":"We Empower Your Business Growth","publisher":{"@id":"https:\/\/pheonixsolutions.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/pheonixsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/pheonixsolutions.com\/blog\/#organization","name":"PheonixSolutions","url":"https:\/\/pheonixsolutions.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pheonixsolutions.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2016\/12\/logo.png","contentUrl":"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2016\/12\/logo.png","width":454,"height":300,"caption":"PheonixSolutions"},"image":{"@id":"https:\/\/pheonixsolutions.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/PheonixSolutions-209942982759387\/","https:\/\/x.com\/pheonixsolution"]},{"@type":"Person","@id":"https:\/\/pheonixsolutions.com\/blog\/#\/schema\/person\/4e85fd49b9effeb3f8d20a4751749d87","name":"kedar p","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3c6a6152b6071b941fa46f5d58caddbf062e588f9a18d0df11ecdea42e964097?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3c6a6152b6071b941fa46f5d58caddbf062e588f9a18d0df11ecdea42e964097?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3c6a6152b6071b941fa46f5d58caddbf062e588f9a18d0df11ecdea42e964097?s=96&r=g","caption":"kedar p"},"url":"https:\/\/pheonixsolutions.com\/blog\/author\/kedar\/"}]}},"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7F4uM-2qL","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/527"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=9347"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/9347\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=9347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=9347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=9347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}