<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: cowefe</title>
    <description>The latest articles on DEV Community by cowefe (@cowefe).</description>
    <link>https://dev.to/cowefe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F862516%2F9378a187-ac8f-4555-9b46-131f947857fd.png</url>
      <title>DEV Community: cowefe</title>
      <link>https://dev.to/cowefe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/cowefe"/>
    <language>en</language>
    <item>
      <title>Warning: Text content did not match in React 18</title>
      <dc:creator>cowefe</dc:creator>
      <pubDate>Sat, 14 May 2022 20:39:29 +0000</pubDate>
      <link>https://dev.to/cowefe/warning-text-content-did-not-match-in-react-18-384h</link>
      <guid>https://dev.to/cowefe/warning-text-content-did-not-match-in-react-18-384h</guid>
      <description>&lt;p&gt;Hello, recently the project I am working on has been upgraded to React 18. By then, suddenly a lot of issues with hydration have started to appear as warnings/errors in the console. The one I'm struggling with is "Warning: Text content did not match":&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.stack.imgur.com/NPqqc.png"&gt;Error&lt;/a&gt;&lt;br&gt;
Code of this component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   &amp;lt;div className="O75-product-faq__questions is-active accordion--initialized"&amp;gt;
                            {
                                dataForSelect.length &amp;gt; 1 &amp;amp;&amp;amp; &amp;lt;h4 className="O75-product-faq__questions__name js-category-name"&amp;gt;{props.questionsByCategories[selectedCategory?.value].name}&amp;lt;/h4&amp;gt;
                            }
                            {
                                props.questionsByCategories[selectedCategory?.value].questions.map((element, i) =&amp;gt; (
                                    &amp;lt;div key={i} className="O75-product-faq__questions__item"&amp;gt;
                                        {(element.question || props.showOnlyAnswer) &amp;amp;&amp;amp; &amp;lt;div className={`O75-product-faq__questions__item__button${openedElement === i ? ' has-accordion-open' : ''}`} onClick={() =&amp;gt; openElement(i)}&amp;gt;{element.question}&amp;lt;/div&amp;gt;}
                                        &amp;lt;AnimateHeight height={openedElement === i ? 'auto' : 0} duration={transitionDisabled ? 0 : 400}&amp;gt;
                                            &amp;lt;div className="O75-product-faq__questions__item__content" dangerouslySetInnerHTML={{ __html: element.answer }} /&amp;gt;
                                        &amp;lt;/AnimateHeight&amp;gt;
                                    &amp;lt;/div&amp;gt;))
                            }
                        &amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I know that this issue results from the difference between client and server side rendering, but I don't know how to fix it and nothing I have found on internet has worked in my case.&lt;/p&gt;

&lt;p&gt;Rest of the file, in case if the issue is not with aforementioned part:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useMemo, useState } from 'react';
import type { ReactElement } from 'react';
import AnimateHeight from 'react-animate-height';
import { BaseSelect, SelectOption } from '../molecules/base-select';
import type { FrequentlyAskedCategory } from './frequentlyAskedQuestion';
import { fromBase64 } from '../shared-services/base64Service';

interface FaqPanelProps {
    mainTitle?: string;
    menuTitle?: string;
    showOnlyAnswer: boolean;
    currentPageUrl: string;
    questionsByCategories: Record&amp;lt;string, FrequentlyAskedCategory&amp;gt;,
    faqStructuredDataBase64: string;
}

const FAQPanel = (props: FaqPanelProps): ReactElement =&amp;gt; {
    const categories = Object.keys(props.questionsByCategories);
    const dataForSelect: Array&amp;lt;SelectOption&amp;gt; = categories.map(key =&amp;gt; ({ label: props.questionsByCategories[key].name, value: key }));
    const noOpenedElementIndex = -1;

    const [openedElement, setOpenedElement] = useState&amp;lt;number&amp;gt;(-1);
    const [selectedCategory, setSelectedCategory] = useState&amp;lt;SelectOption&amp;gt;(dataForSelect.length &amp;gt; 0 ? dataForSelect[0] : null);
    const [transitionDisabled, setTransitionDisabled] = useState&amp;lt;boolean&amp;gt;(false);
    const parsedStructuredData = useMemo(() =&amp;gt; {
        if(props.faqStructuredDataBase64 != null &amp;amp;&amp;amp; props.faqStructuredDataBase64 !== ""){
           return fromBase64(props.faqStructuredDataBase64);
        }

        return "";
    }, [props.faqStructuredDataBase64]);

    const selectNewCategory = (option: SelectOption): void =&amp;gt; {
        setTransitionDisabled(true);
        setOpenedElement(noOpenedElementIndex);
        setSelectedCategory(option);
    }

    const openElement = (index: number): void =&amp;gt; {
        if (transitionDisabled) {
            setTransitionDisabled(false);
        }
        setOpenedElement(index === openedElement ? noOpenedElementIndex : index);
    }

    const speakableJson = JSON.stringify({
        "@context": "https://schema.org/",
        "@type": "WebPage",
        "name": props.mainTitle,
        "speakable":
            [".O75-product-faq__headline",
                ".O75-product-faq__questions__item"],
        "url": props.currentPageUrl
    });

    const hasFAQStructuredData = parsedStructuredData != null &amp;amp;&amp;amp; parsedStructuredData !== "";
    return (
        &amp;lt;div className="container"&amp;gt;
            &amp;lt;section className="O75-product-faq" &amp;gt;
                {
                    props.mainTitle
                        ? &amp;lt;h2 className="O75-product-faq__headline"&amp;gt;{props.mainTitle}&amp;lt;/h2&amp;gt;
                        : &amp;lt;h4 className="O75-product-faq__categories-headline"&amp;gt;{props.menuTitle}&amp;lt;/h4&amp;gt;
                }
                &amp;lt;div className="flex"&amp;gt;
                    {dataForSelect.length &amp;gt; 1 &amp;amp;&amp;amp;
                        &amp;lt;div className="O75-product-faq__categories"&amp;gt;
                            &amp;lt;div className="filter__list is-hidden-sm filter"&amp;gt;
                                {
                                    dataForSelect.map((element, i) =&amp;gt; (
                                        &amp;lt;button className={`filter__btn js-filter__btn${element.value === selectedCategory?.value ? " is-active" : ""}`} key={i} onClick={() =&amp;gt; selectNewCategory(element)}&amp;gt;
                                            {element.label}
                                        &amp;lt;/button&amp;gt;))
                                }
                            &amp;lt;/div&amp;gt;
                            &amp;lt;div className="filter__group is-hidden-md"&amp;gt;
                                &amp;lt;BaseSelect selectedValue={selectedCategory}
                                    handleChange={selectNewCategory}
                                    options={dataForSelect} /&amp;gt;
                            &amp;lt;/div&amp;gt;
                        &amp;lt;/div&amp;gt;
                    }
                    {categories.length &amp;gt; 0 &amp;amp;&amp;amp;
                        &amp;lt;div className="O75-product-faq__questions is-active accordion--initialized"&amp;gt;
                            {
                                dataForSelect.length &amp;gt; 1 &amp;amp;&amp;amp; &amp;lt;h4 className="O75-product-faq__questions__name js-category-name"&amp;gt;{props.questionsByCategories[selectedCategory?.value].name}&amp;lt;/h4&amp;gt;
                            }
                            {
                                props.questionsByCategories[selectedCategory?.value].questions.map((element, i) =&amp;gt; (
                                    &amp;lt;div key={i} className="O75-product-faq__questions__item"&amp;gt;
                                        {(element.question || props.showOnlyAnswer) &amp;amp;&amp;amp; &amp;lt;div className={`O75-product-faq__questions__item__button${openedElement === i ? ' has-accordion-open' : ''}`} onClick={() =&amp;gt; openElement(i)}&amp;gt;{element.question}&amp;lt;/div&amp;gt;}
                                        &amp;lt;AnimateHeight height={openedElement === i ? 'auto' : 0} duration={transitionDisabled ? 0 : 400}&amp;gt;
                                            &amp;lt;div className="O75-product-faq__questions__item__content" dangerouslySetInnerHTML={{ __html: element.answer }} /&amp;gt;
                                        &amp;lt;/AnimateHeight&amp;gt;
                                    &amp;lt;/div&amp;gt;))
                            }
                        &amp;lt;/div&amp;gt;
                    }
                &amp;lt;/div&amp;gt;
                {hasFAQStructuredData &amp;amp;&amp;amp; &amp;lt;script suppressHydrationWarning type="application/ld+json" dangerouslySetInnerHTML={{__html:parsedStructuredData } }&amp;gt;&amp;lt;/script&amp;gt;}
                &amp;lt;script suppressHydrationWarning type="application/ld+json" dangerouslySetInnerHTML={{__html: speakableJson}} &amp;gt;&amp;lt;/script&amp;gt;
            &amp;lt;/section&amp;gt;
        &amp;lt;/div&amp;gt;
    )
}

export { FAQPanel };
export type { FaqPanelProps }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Link to code on stackblitz for better readability: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://stackblitz.com/edit/react-ts-xdbemj?file=index.tsx"&gt;File&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Does anyone knows how to fix this? I have totally ran out of ideas.&lt;/p&gt;

</description>
      <category>react</category>
    </item>
  </channel>
</rss>
