{"id":2408,"date":"2019-12-23T09:46:25","date_gmt":"2019-12-23T08:46:25","guid":{"rendered":"https:\/\/pagepro.co\/blog\/?p=2408"},"modified":"2024-11-25T09:10:28","modified_gmt":"2024-11-25T08:10:28","slug":"what-is-react-context-and-how-to-use-it","status":"publish","type":"post","link":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/","title":{"rendered":"What is React Context And How To Use It?"},"content":{"rendered":"\n<p>If you&#8217;re having a problem with passing property to a component just to pass it further down to child, <a href=\"https:\/\/reactjs.org\/docs\/context.html\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">React Context<\/a> is exactly what you need.<\/p>\n\n\n\n<p>By the definition, React Context provides us with a possibility to pass data through the component tree, so you don\u2019t need to pass props down manually at every level. <\/p>\n\n\n\n<p>In other words, we can compare context to a global object of our <a href=\"https:\/\/pagepro.co\/services\/reactjs-development\" target=\"_blank\" rel=\"noreferrer noopener\">React App<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"prop-drilling-problem\">Prop drilling problem<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"515\" src=\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/pasted-image-0-1024x515.png\" alt=\"Tree structure components without context\" class=\"wp-image-2409\" srcset=\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/pasted-image-0-1024x515.png 1024w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/pasted-image-0-300x151.png 300w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/pasted-image-0-768x386.png 768w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/pasted-image-0-500x251.png 500w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/pasted-image-0-324x163.png 324w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/pasted-image-0.png 1096w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>React components structure is like a tree. Each child has only one parent and everyone is connected to the main root component. Thanks to this structure we have only one direction flow \u2014 we can pass props from top to bottom. <\/p>\n\n\n\n<p>When we need to pass prop through a lot of components (f.ex from root to A3) it becomes a little bit annoying, and we called it a prop drilling problem. React Context comes to the rescue.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"979\" height=\"492\" src=\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/withcontext.png\" alt=\"Tree structure components with context\" class=\"wp-image-2410\" srcset=\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/withcontext.png 979w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/withcontext-300x151.png 300w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/withcontext-768x386.png 768w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/withcontext-500x251.png 500w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/withcontext-324x163.png 324w\" sizes=\"(max-width: 979px) 100vw, 979px\" \/><\/figure>\n\n\n\n<p>When we need to make some of the data global in our app, or we would like to use them in a few components on a different deeply nested level in the app structure, we definitely should use React Context. <\/p>\n\n\n\n<p>It gives us access to the data on each level of our React App tree structure.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-create-context\">How to create Context?<\/h2>\n\n\n\n<p>The way of creating context is to import <code>createContext<\/code> the method from React library and invoke it with <code>defaultValue<\/code> &#8211; it is not required but can be helpful when a component has not matched Provider in the tree. <\/p>\n\n\n\n<p>Moreover, using <code>defaultValue<\/code> during creating React Context is important in testing components as separated from others.<\/p>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"javascript\">import { createContext } from 'react'\ncreateContext('defaultValue')<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-of-creating-context\">Example of creating Context<\/h2>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">export const CountryContext = createContext({})\nexport const LanguageContext = createContext('en')\n<\/code><\/pre>\n\n\n\n<p><strong>TIP:<\/strong> Good practice is to have a separate files for creating contexts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-can-we-pass-down-context\">How can we pass down Context?<\/h2>\n\n\n\n<p>Create Context method returns an object with Provider and Consumer. <\/p>\n\n\n\n<p>Thanks to Provider we can pass props down in our app structure. Provider component has a prop &#8211; <code>value<\/code> &#8211; which allows us to pass data assigned to this prop to all descendants <em>(in <code>value<\/code> we can pass an object, number, function etc&#8230;)<\/em>. One Provider can be connected to many consumers. <\/p>\n\n\n\n<p>Furthermore, Provider can be nested, thanks to that we can override passed data in <code>value<\/code> prop deeper within the app. <\/p>\n\n\n\n<p>If <code>value<\/code> prop changes all consumers of a Provider will re-rendered.<\/p>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">const { Provider } = createContext('defaultValue')<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-of-using-provider\">Example of using Provider<\/h2>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">&lt;CountryContext.Provider\n  value={{\n     setSelectedCountry,\n     selectedCountry\n   }}\n>\n  &lt;LanguageContext.Provider\n    value={{\n       lang: selectedLanguage,\n       setSelectedLanguage\n     }}\n  >\n    &lt;header> ...\n    &lt;main> ...\n    &lt;footer>... \n  &lt;LanguageContext.Provider>\n&lt;\/CountryContext.Provider><\/code><\/pre>\n\n\n\n<div class=\"wp-block-code-mind-cta c-cta-block\" style=\"background-color:;color:\"><div class=\"c-cta-block__content\"><p class=\"c-cta-block__title\">WANT TO USE REACT IN YOUR PROJECT? <\/p><div class=\"c-cta-block__action\"><a href=\"https:\/\/pagepro.co\/consultation\" class=\"c-cta-block__button ga-cta ga-cta-consultation theme-bg-3\">SCHEDULE A FREE CALL WITH OUR EXPERT. <\/a><\/div><\/div><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-can-we-get-context\">How can we get Context?<\/h2>\n\n\n\n<p>We can have access to data which we passed to <code>value<\/code> prop in Provider thanks to subscriber called Consumer. <\/p>\n\n\n\n<p>The Consumer component requires a function as a child that has the context current value in an argument and returns a React Node element. <\/p>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"javascript\">const { Consumer } = createContext('defaultValue')<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-of-using-context-by-consumer\">Example of using context by Consumer<\/h2>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">&lt;CountryContext.Consumer>\n  {({ selectedCountry }) => (\n    &lt;h1>\n      {selectedCountry.name}\n    &lt;\/h1>\n  )}\n&lt;\/CountryContext.Consumer><\/code><\/pre>\n\n\n\n<p>In this example we use <code>CountryContext<\/code> to have access to selected country. We create function returning country name which we received in an argument of it <em>(the newest applied context)<\/em>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-of-using-context-consumer-as-a-hook\">Example of using Context Consumer as a hook<\/h2>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">import React, { useState, useContext } from 'react'\nimport axios from 'axios'\nimport { CountryContext } from '.\/contexts'\nimport { pushErrorNotification } from '.\/utils'\n\nconst SearchBox = () => {\n  const [searchValue, setSearchValue] = useState('')\n  const {\n    setSelectedCountry\n  } = useContext(CountryContext)\n\n  const searchCountry = () => {\n    axios.get(`${endpoint}${searchValue}`)\n      .then(({ data }) => {\n        setSelectedCountry(data)\n      })\n      .catch(() => pushErrorNotification('Sth went wrong.'))\n  }\n\n  return (\n    &lt;div className=\"search-wrapper\">\n      &lt;input\n        type=\"text\"\n        id=\"search\"\n        name=\"search\"\n        value={searchValue}\n        placeholder=\"Search for...\"\n        onChange={({ target }) => setSearchValue(target.value)}\n      \/>\n      &lt;button onClick={() => searchCountry()}>\n        Search\n      &lt;\/button>\n    &lt;\/div>  \n  )\n}\n\nexport default SearchBox<\/code><\/pre>\n\n\n\n<p>Here we have a <code>SearchBox<\/code> component where we can type desirable country name and find some info about it. Thanks to <code>useContext<\/code> hook, we can quickly set found country on current displaying details by <code>setSelectedCountry<\/code> method.<\/p>\n\n\n\n<div class=\"c-newsletter-block-acf\">\n    <p class=\"c-newsletter-block-acf__title c-newsletter__header\">\n        EXPERT INSIGHTS, FRICTIONLESSLY DELIVERED!     <\/p>\n    <p class=\"c-newsletter-block-acf__desc c-newsletter__header\">\n        Curated tech news delivered straight to your inbox every month.\r\n    <\/p>\n    <form method=\"post\" class=\"c-newsletter-block-acf__form js-newsletter-form c-newsletter__action\" name=\"newsletter-block-form\">\n        <input name=\"newsletter-email\" id=\"newsletter-email\" type=\"text\" class=\"c-newsletter-block-acf__input js-newsletter-input\" placeholder=\"Company Email\" \/>\n        <input name=\"newsletter-campaign\" id=\"newsletter-campaign\" type=\"hidden\" value=\"\" \/>\n        <div class=\"c-newsletter-block-acf__group\">\n            <input name=\"consent\" id=\"consent\" type=\"checkbox\" class=\"js-newsletter-consent\" \/>\n            <label class=\"c-newsletter-block-acf__label\" for=\"consent\">I accept the <a href=\"https:\/\/pagepro.co\/privacy-policy\">Privacy Policy<\/a> and agree to process my personal data by Pagepro for marketing purposes.<\/label>\n        <\/div>\n        <input type=\"submit\" class=\"c-newsletter-block-acf__button button js-newsletter-sub ga-newsletter-form-content\" value=\"Sign up\" \/>\n        <p class=\"theme-size-1 js-message-valid is-hidden is-invalid\"><\/p>\n    <\/form>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"easy-access-to-context\">Easy access to Context<\/h2>\n\n\n\n<p>In the documentation, we can read that: <\/p>\n\n\n\n<p><em>The contextType property on a class can be assigned a Context object created by React.createContext(). <\/em><\/p>\n\n\n\n<p><em>This lets you consume the nearest current value of that Context type using this.context. You can reference this in any of the lifecycle methods including the render function.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">ComponentA.contextType = ContextB\nOR\nstatic contextType = ContextB<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-of-using-context-by-this\">Example of using context by \u2018this\u2019<\/h2>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">static contextType = CountryContext\n\nrender () {\n  const {\n    selectedCountry,\n    selectedCountry: {\n      borders = []\n    }\n   } = this.context\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">import React from 'react'\nimport { CountryContext } from '.\/contexts'\n\nclass CountryDetails extends React.Component {  \n  render () {\n    const {\n       selectedCountry: {\n         capital,\n         region,\n         subregion,\n         area,\n         population,\n         timezones = []\n       }\n     } = this.context\n\n     return (\n       &lt;div> ...\n     )\n  }  \n}\n\nCountryDetails.contextType = CountryContext\n\nexport default CountryDetails<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"make-work-debugging-faster\">Make work\/debugging faster<\/h2>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">CountryContext.displayName = 'SelectedCountry'<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"633\" height=\"148\" src=\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/context-1.png\" alt=\"context.provider app layout\" class=\"wp-image-2419\" srcset=\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/context-1.png 633w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/context-1-300x70.png 300w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/context-1-500x117.png 500w, https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2019\/12\/context-1-324x76.png 324w\" sizes=\"(max-width: 633px) 100vw, 633px\" \/><figcaption class=\"wp-element-caption\"><br><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-of-using-multiple-contexts\">Example of using multiple contexts <\/h2>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">import React, { useContext } from 'react'\nimport { CountryContext, LanguageContext } from '.\/contexts'\n\n\n\/\/ using hook in stateless components\nconst Languages = () => {  \n    const {\n        selectedCountry: {\n            languages = []\n        }\n    } = useContext(CountryContext)\n\n    const {\n        lang\n    } = useContext(LanguageContext)\n\n    return (\n        &lt;div>...\n    )\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code-mind-code c-code\"><code class=\"jsx\">\/\/ using Consumer component f.ex. in class components\n&lt;CountryContext.Consumer>\n  {({ selectedCountry }) => (\n    &lt;LanguageContext.Consumer>\n      {({ lang }) => {\n\t      &lt;div> ...\n        }\n\t  }\n    &lt;\/LanguageContext.Consumer>\n  )}\n &lt;\/CountryContext.Consumer><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"summary\">Summary<\/h2>\n\n\n\n<p>React Context is a very approachable and helpful API for managing state over multiple components. <\/p>\n\n\n\n<p>It gives us the possibility to share some variables through the whole app without passing props down each time we need them. <\/p>\n\n\n\n<p>It makes work faster and easier in every <a href=\"https:\/\/pagepro.co\/react-development.html\" target=\"_blank\" rel=\"noreferrer noopener\">React agency<\/a> by accessing data everywhere across the app.<\/p>\n\n\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re having a problem with passing property to a component just to pass it further down to child, React Context is exactly what you need.<\/p>\n","protected":false},"author":16,"featured_media":6618,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76,84],"tags":[21,262,53],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is React Context And How To Use It? - Pagepro<\/title>\n<meta name=\"description\" content=\"If you&#039;re having a problem with passing property to a component just to pass it further down to child, React Context is exactly what you need.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is React Context And How To Use It? - Pagepro\" \/>\n<meta property=\"og:description\" content=\"If you&#039;re having a problem with passing property to a component just to pass it further down to child, React Context is exactly what you need.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/\" \/>\n<meta property=\"og:site_name\" content=\"Pagepro\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/thisispagepro\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-23T08:46:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-25T08:10:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2021\/04\/ReactPicture.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"682\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jakub Dakowicz\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jakub Dakowicz\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/\"},\"author\":{\"name\":\"Jakub Dakowicz\",\"@id\":\"https:\/\/pagepro.co\/blog\/#\/schema\/person\/66e00cf32ef7d2d1b010523eff380caf\"},\"headline\":\"What is React Context And How To Use It?\",\"datePublished\":\"2019-12-23T08:46:25+00:00\",\"dateModified\":\"2024-11-25T08:10:28+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/\"},\"wordCount\":648,\"publisher\":{\"@id\":\"https:\/\/pagepro.co\/blog\/#organization\"},\"keywords\":[\"components\",\"context\",\"react\"],\"articleSection\":[\"Product Development\",\"React JS\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/\",\"url\":\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/\",\"name\":\"What is React Context And How To Use It? - Pagepro\",\"isPartOf\":{\"@id\":\"https:\/\/pagepro.co\/blog\/#website\"},\"datePublished\":\"2019-12-23T08:46:25+00:00\",\"dateModified\":\"2024-11-25T08:10:28+00:00\",\"description\":\"If you're having a problem with passing property to a component just to pass it further down to child, React Context is exactly what you need.\",\"breadcrumb\":{\"@id\":\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/pagepro.co\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Blog\",\"item\":\"https:\/\/pagepro.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"What is React Context And How To Use It?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/pagepro.co\/blog\/#website\",\"url\":\"https:\/\/pagepro.co\/blog\/\",\"name\":\"Pagepro\",\"description\":\"Frictionless Next.js, Expo &amp; Sanity Development Blog\",\"publisher\":{\"@id\":\"https:\/\/pagepro.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/pagepro.co\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/pagepro.co\/blog\/#organization\",\"name\":\"Pagepro\",\"url\":\"https:\/\/pagepro.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/pagepro.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2020\/08\/logo_pagepro-b66d228a1e-1.png\",\"contentUrl\":\"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2020\/08\/logo_pagepro-b66d228a1e-1.png\",\"width\":440,\"height\":200,\"caption\":\"Pagepro\"},\"image\":{\"@id\":\"https:\/\/pagepro.co\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/thisispagepro\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/pagepro.co\/blog\/#\/schema\/person\/66e00cf32ef7d2d1b010523eff380caf\",\"name\":\"Jakub Dakowicz\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/pagepro.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5e0855c6f563f4e1a4a53206089ce0cc?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5e0855c6f563f4e1a4a53206089ce0cc?s=96&d=mm&r=g\",\"caption\":\"Jakub Dakowicz\"},\"description\":\"Jakub is the Chief Technology Officer at Pagepro, where he leads technical strategy and oversees the architecture of complex web platforms built with Next.js and headless CMS solutions. With nearly nine years at Pagepro and over five years leading the engineering team, he has been instrumental in shaping the company\u2019s architectural standards, development workflows, and scalability practices. Jakub focuses on building robust, composable systems that balance performance, maintainability, and long-term business flexibility. He drives technical decision-making across projects, ensuring that solutions are not only modern, but strategically aligned with client growth.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/jakub-dakowicz-939838102\/\"],\"url\":\"https:\/\/pagepro.co\/blog\/author\/jakub_dakowicz\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is React Context And How To Use It? - Pagepro","description":"If you're having a problem with passing property to a component just to pass it further down to child, React Context is exactly what you need.","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:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/","og_locale":"en_US","og_type":"article","og_title":"What is React Context And How To Use It? - Pagepro","og_description":"If you're having a problem with passing property to a component just to pass it further down to child, React Context is exactly what you need.","og_url":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/","og_site_name":"Pagepro","article_publisher":"https:\/\/www.facebook.com\/thisispagepro","article_published_time":"2019-12-23T08:46:25+00:00","article_modified_time":"2024-11-25T08:10:28+00:00","og_image":[{"width":1200,"height":682,"url":"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2021\/04\/ReactPicture.png","type":"image\/png"}],"author":"Jakub Dakowicz","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jakub Dakowicz","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/#article","isPartOf":{"@id":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/"},"author":{"name":"Jakub Dakowicz","@id":"https:\/\/pagepro.co\/blog\/#\/schema\/person\/66e00cf32ef7d2d1b010523eff380caf"},"headline":"What is React Context And How To Use It?","datePublished":"2019-12-23T08:46:25+00:00","dateModified":"2024-11-25T08:10:28+00:00","mainEntityOfPage":{"@id":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/"},"wordCount":648,"publisher":{"@id":"https:\/\/pagepro.co\/blog\/#organization"},"keywords":["components","context","react"],"articleSection":["Product Development","React JS"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/","url":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/","name":"What is React Context And How To Use It? - Pagepro","isPartOf":{"@id":"https:\/\/pagepro.co\/blog\/#website"},"datePublished":"2019-12-23T08:46:25+00:00","dateModified":"2024-11-25T08:10:28+00:00","description":"If you're having a problem with passing property to a component just to pass it further down to child, React Context is exactly what you need.","breadcrumb":{"@id":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/pagepro.co\/blog\/what-is-react-context-and-how-to-use-it\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/pagepro.co\/"},{"@type":"ListItem","position":2,"name":"Blog","item":"https:\/\/pagepro.co\/blog\/"},{"@type":"ListItem","position":3,"name":"What is React Context And How To Use It?"}]},{"@type":"WebSite","@id":"https:\/\/pagepro.co\/blog\/#website","url":"https:\/\/pagepro.co\/blog\/","name":"Pagepro","description":"Frictionless Next.js, Expo &amp; Sanity Development Blog","publisher":{"@id":"https:\/\/pagepro.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/pagepro.co\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/pagepro.co\/blog\/#organization","name":"Pagepro","url":"https:\/\/pagepro.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pagepro.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2020\/08\/logo_pagepro-b66d228a1e-1.png","contentUrl":"https:\/\/pagepro.co\/blog\/wp-content\/uploads\/2020\/08\/logo_pagepro-b66d228a1e-1.png","width":440,"height":200,"caption":"Pagepro"},"image":{"@id":"https:\/\/pagepro.co\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/thisispagepro"]},{"@type":"Person","@id":"https:\/\/pagepro.co\/blog\/#\/schema\/person\/66e00cf32ef7d2d1b010523eff380caf","name":"Jakub Dakowicz","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pagepro.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5e0855c6f563f4e1a4a53206089ce0cc?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5e0855c6f563f4e1a4a53206089ce0cc?s=96&d=mm&r=g","caption":"Jakub Dakowicz"},"description":"Jakub is the Chief Technology Officer at Pagepro, where he leads technical strategy and oversees the architecture of complex web platforms built with Next.js and headless CMS solutions. With nearly nine years at Pagepro and over five years leading the engineering team, he has been instrumental in shaping the company\u2019s architectural standards, development workflows, and scalability practices. Jakub focuses on building robust, composable systems that balance performance, maintainability, and long-term business flexibility. He drives technical decision-making across projects, ensuring that solutions are not only modern, but strategically aligned with client growth.","sameAs":["https:\/\/www.linkedin.com\/in\/jakub-dakowicz-939838102\/"],"url":"https:\/\/pagepro.co\/blog\/author\/jakub_dakowicz\/"}]}},"acf":[],"_links":{"self":[{"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/posts\/2408"}],"collection":[{"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/comments?post=2408"}],"version-history":[{"count":21,"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/posts\/2408\/revisions"}],"predecessor-version":[{"id":18466,"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/posts\/2408\/revisions\/18466"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/media\/6618"}],"wp:attachment":[{"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/media?parent=2408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/categories?post=2408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pagepro.co\/blog\/wp-json\/wp\/v2\/tags?post=2408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}