<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Cannot read properties of null (useContext) in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Cannot-read-properties-of-null-useContext/m-p/1176075#M43539</link>
    <description>&lt;P&gt;Thanks so much, Brandon, for taking the time to respond to my question! I really appreciate it!&lt;/P&gt;</description>
    <pubDate>Mon, 14 Jul 2025 09:10:10 GMT</pubDate>
    <dc:creator>jay_pinetco</dc:creator>
    <dc:date>2025-07-14T09:10:10Z</dc:date>
    <item>
      <title>Cannot read properties of null (useContext)</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Cannot-read-properties-of-null-useContext/m-p/1174856#M43513</link>
      <description>&lt;P&gt;Hey People,&lt;/P&gt;
&lt;P&gt;I am using HubSpot CMS React and trying to use components from the UI Library ( You can consider PrimeReact, ANT Design, Material UI ) inside a HubSpot Island, but I get errors like: "Cannot read properties of null (useContext)." I think the issue is that some UI components need setup that isn't available inside an island. How can I use a UI component library inside HubSpot CMS React, especially inside a HubSpot Island? Are there any best practices or things I should avoid?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Jul 2025 09:26:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Cannot-read-properties-of-null-useContext/m-p/1174856#M43513</guid>
      <dc:creator>jay_pinetco</dc:creator>
      <dc:date>2025-07-10T09:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot read properties of null (useContext)</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Cannot-read-properties-of-null-useContext/m-p/1174949#M43518</link>
      <description>&lt;P&gt;You’re absolutely right that using UI component libraries like PrimeReact, Ant Design, or Material UI &lt;EM&gt;inside HubSpot Islands&lt;/EM&gt; introduces challenges—especially around context providers, client-side hydration, and DOM assumptions.&lt;/P&gt;&lt;P&gt;HubSpot Islands in the CMS React framework are intentionally &lt;STRONG&gt;isolated React environments&lt;/STRONG&gt; that are server-rendered and then hydrated on the client, which can interfere with component libraries that rely on React.createContext, global DOM references, or window-based setup during initialization.&lt;/P&gt;&lt;H3&gt;&amp;nbsp;What’s Causing useContext(null) Errors?&lt;/H3&gt;&lt;P&gt;Those errors typically mean a provider (like ThemeProvider, ConfigProvider, or CssBaseline) &lt;STRONG&gt;isn’t wrapping your Island component&lt;/STRONG&gt;, or the provider initialization is breaking due to mismatched hydration. Some UI libraries need to read or write to the DOM immediately when the component is loaded—and that breaks in Islands unless carefully scoped.&lt;/P&gt;&lt;H3&gt;&amp;nbsp;&lt;/H3&gt;&lt;H3&gt;Best Practices for Using Component Libraries in HubSpot Islands:&lt;/H3&gt;&lt;OL&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Wrap Islands with Context Providers Manually&lt;/STRONG&gt;&lt;BR /&gt;Set up a wrapper for your Island that initializes required providers:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;import&lt;/SPAN&gt; { &lt;SPAN class=""&gt;ConfigProvider&lt;/SPAN&gt; } &lt;SPAN class=""&gt;from&lt;/SPAN&gt; &lt;SPAN class=""&gt;'antd'&lt;/SPAN&gt;; &lt;SPAN class=""&gt;const&lt;/SPAN&gt; &lt;SPAN class=""&gt;MyIsland&lt;/SPAN&gt; = () =&amp;gt; { &lt;SPAN class=""&gt;return&lt;/SPAN&gt; ( &lt;SPAN class=""&gt;&amp;lt;ConfigProvider&lt;/SPAN&gt; &lt;SPAN class=""&gt;theme&lt;/SPAN&gt;=&lt;SPAN class=""&gt;{{}}&lt;/SPAN&gt;&amp;gt; &lt;SPAN class=""&gt;&amp;lt;MyComponent&lt;/SPAN&gt; /&amp;gt; &lt;SPAN class=""&gt;&amp;lt;/ConfigProvider&lt;/SPAN&gt;&amp;gt; ); }; &lt;SPAN class=""&gt;export&lt;/SPAN&gt; &lt;SPAN class=""&gt;default&lt;/SPAN&gt; &lt;SPAN class=""&gt;MyIsland&lt;/SPAN&gt;; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;Do this inside the React file you reference in the Island.&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Avoid SSR-Dependent Components&lt;/STRONG&gt;&lt;BR /&gt;Some components like modals, tooltips, or theme managers depend on document.body or window. These won’t render correctly in SSR without extra steps. You can:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Use useEffect to delay rendering&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Use dynamic imports (e.g. next/dynamic style)&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Wrap in conditional hydration guards&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Isolate Side Effects&lt;/STRONG&gt;&lt;BR /&gt;Avoid running DOM-affecting scripts directly inside the render tree. Instead:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;useEffect&lt;/SPAN&gt;(&lt;SPAN class=""&gt;() =&amp;gt;&lt;/SPAN&gt; { &lt;SPAN class=""&gt;if&lt;/SPAN&gt; (&lt;SPAN class=""&gt;typeof&lt;/SPAN&gt; &lt;SPAN class=""&gt;window&lt;/SPAN&gt; !== &lt;SPAN class=""&gt;"undefined"&lt;/SPAN&gt;) { &lt;SPAN class=""&gt;// Safe DOM-related code here&lt;/SPAN&gt; } }, []); &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Hydration Check&lt;/STRONG&gt;&lt;BR /&gt;Some folks use a “hydration-ready” check before rendering complex libraries:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;const&lt;/SPAN&gt; [isClient, setIsClient] = &lt;SPAN class=""&gt;useState&lt;/SPAN&gt;(&lt;SPAN class=""&gt;false&lt;/SPAN&gt;); &lt;SPAN class=""&gt;useEffect&lt;/SPAN&gt;(&lt;SPAN class=""&gt;() =&amp;gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;setIsClient&lt;/SPAN&gt;(&lt;SPAN class=""&gt;true&lt;/SPAN&gt;), []); &lt;SPAN class=""&gt;return&lt;/SPAN&gt; isClient ? &lt;SPAN class=""&gt;&amp;lt;YourComplexUI&lt;/SPAN&gt; /&amp;gt; : &lt;SPAN class=""&gt;null&lt;/SPAN&gt;; &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;&lt;STRONG&gt;Consider Using Only Lightweight Components in Islands&lt;/STRONG&gt;&lt;BR /&gt;Heavy UI frameworks can bloat page load times or break if they depend on global scope. If you just need buttons, inputs, or modals, consider using &lt;A class="" href="https://developers.hubspot.com/docs/reference/ui-components/overview" target="_new" rel="noopener"&gt;HubSpot’s UI Components SDK&lt;/A&gt; instead for built-in harmony.&lt;/P&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;H3&gt;Things to Avoid&lt;/H3&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;Don’t mix React versions between your Island and library (HubSpot CMS React uses React 18).&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;Avoid injecting external libraries globally into the page if you’re working within Islands—they won't scope safely and may conflict with HubSpot's runtime.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;H3&gt;Dev Sandbox Tip:&lt;/H3&gt;&lt;P&gt;If you’re testing, spin up a HubSpot &lt;A class="" href="https://developers.hubspot.com/docs/cms/developer-reference/testing-sites" target="_new" rel="noopener"&gt;developer sandbox&lt;/A&gt; and try loading your components in isolation from a full page module vs. an Island. Some libraries will behave better outside of the Island scope.&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;FONT&gt;Let me know if this helps, or if you have any other questions!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;SPAN class="lia-unicode-emoji"&gt;&lt;FONT&gt;&lt;span class="lia-unicode-emoji" title=":heavy_check_mark:"&gt;✔️&lt;/span&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT&gt;Was I able to help answer your question? Help the community by&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;marking it as a solution.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE width="100%"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="20.365535248041773%" height="191px"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrandonWoodruff_0-1752152806617.jpeg" style="width: 400px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/150366iB155EFFA00C09E04/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BrandonWoodruff_0-1752152806617.jpeg" alt="BrandonWoodruff_0-1752152806617.jpeg" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;TD width="79.50391644908615%" height="191px"&gt;&lt;P&gt;&lt;STRONG&gt;&lt;A href="https://www.linkedin.com/in/brandon-woody-woodruff/" target="_blank" rel="noopener nofollow noreferrer"&gt;&lt;FONT&gt;Brandon Woodruff&lt;/FONT&gt;&lt;/A&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;FONT&gt;Senior Software Developer @&lt;A href="https://www.pearagon.com/" target="_blank" rel="nofollow noopener noreferrer"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Pearagon&lt;/A&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Still have questions? Reach out to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;A href="mailto:brandon@pearagon.com" target="_blank" rel="noopener nofollow noreferrer"&gt;&lt;FONT&gt;brandon@pearagon.com&lt;/FONT&gt;&lt;/A&gt;&lt;/P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BrandonWoodruff_1-1752152806547.png" style="width: 200px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/150365iB3BE4F7092AFED39/image-size/small?v=v2&amp;amp;px=200" role="button" title="BrandonWoodruff_1-1752152806547.png" alt="BrandonWoodruff_1-1752152806547.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;</description>
      <pubDate>Thu, 10 Jul 2025 13:07:28 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Cannot-read-properties-of-null-useContext/m-p/1174949#M43518</guid>
      <dc:creator>BrandonWoodruff</dc:creator>
      <dc:date>2025-07-10T13:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot read properties of null (useContext)</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Cannot-read-properties-of-null-useContext/m-p/1176075#M43539</link>
      <description>&lt;P&gt;Thanks so much, Brandon, for taking the time to respond to my question! I really appreciate it!&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jul 2025 09:10:10 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Cannot-read-properties-of-null-useContext/m-p/1176075#M43539</guid>
      <dc:creator>jay_pinetco</dc:creator>
      <dc:date>2025-07-14T09:10:10Z</dc:date>
    </item>
  </channel>
</rss>

