Skip to content

Render different component for ssr mode and client side  #85

Closed
@peppescg

Description

@peppescg

Hi, I have a strange behavior. I want render a component in server side mode using user agent, but in client I want use media query, beacuse it is possible that bowser client is resized on a mobile width.
With js disabled it works well, but if it is enabled I have a warning in console

{  userAgent.desktop ?
        (
          <Media query="(min-width: 768px)" >
            {matches =>
              matches ? (
                <div>Desktop <LmProductDesktop data={data}/></div>
              ) : (
                <div>Mobile <LmProductMobile data={data}/></div>
              )
            }
          </Media>
        ) :
        (
          <Media query="(max-width: 767px)" >
             {matches =>
               matches ? (
                  <div>Mobile <LmProductMobile data={data}/></div>
               ) : (
                 <div>Desktop <LmProductDesktop data={data}/></div>
               )
             }
          </Media>
       )
 }

Now I am in desktop mode, so I rendered ssr desktop component, in the client with browser resized, I have the warning, in the dom elments I saw the correct css of mobile component, but the desktop component wrapped into media tag, the media mathched is setted to false and if I set true I saw the desktop component not the mobile.

Warning: Text content did not match. Server: "Desktop " Client: "Mobile "

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions