Giter Club home page Giter Club logo

Comments (2)

dousaitis avatar dousaitis commented on August 17, 2024

Hi @rajatjasuja23,

I also use Redux and SSR in my apps and I faced exactly the same issue. In my case I just added an extra prop hasLoaded that indicates that data has already been loaded:

Server Side:

const preloadedState = {
  links: {
    items: [],
    isLoading: false,
    hasLoaded: false,
    hasErrored: false,
  },
  ...
}

In my component now I check if links.hasLoaded === true and If evaluates to true I don't display any Skeleton Screens.

import React from 'react'
import PropTypes from 'prop-types'
import { Skeleton } from 'react-skeleton-screen'
import 'react-skeleton-screen/scss/Skeleton.scss'
import Link from './Link'

const LinkList = ({ linkCategories, links }) => {

  if (links.hasErrored) {
    return <p>Sorry! There was an error loading the items</p>
  }

  if ((links.isLoading || linkCategories.isLoading) &&
      (!links.hasLoaded || !linkCategories.hasLoaded)) {
    return (
      <div>
        <Skeleton width="160px" height="30px" />
        <Skeleton width="70%" height="25px" marginLeft="30px" />
        <Skeleton width="60%" height="25px" marginLeft="30px" />
        <Skeleton width="110px" height="30px" />
        <Skeleton width="55%" height="25px" marginLeft="30px" />
        <Skeleton width="140px" height="30px" />
        <Skeleton width="55%" height="25px" marginLeft="30px" />
        <Skeleton width="65%" height="25px" marginLeft="30px" />
        <Skeleton width="90px" height="30px" />
        <Skeleton width="80%" height="25px" marginLeft="30px" />
        <Skeleton width="65%" height="25px" marginLeft="30px" />
      </div>
    )
  }

  return (
    <div>
      {
        linkCategories.hasLoaded && links.hasLoaded && linkCategories.items.map((category) =>
          links.items.some(link => link.category === category.id) &&
            <div
              className="links"
              key={category.id}
            >
              <h3>{category.name}</h3>
              <ul>
                {
                  links.items.filter(link => link.category === category.id).map(link =>
                    <li key={link.id}>
                      <Link
                        url={link.url}
                        title={link.title}
                        by={link.by}
                      />
                    </li>
                  )
                }
              </ul>
            </div>
      )}
    </div>
  )
}

LinkList.propTypes = {
  links: PropTypes.object.isRequired,
  linkCategories: PropTypes.object.isRequired
}

export default LinkList
  1. If you hit the SSR version of https://johndous.com/useful-links you will NOT see any Skeleton Screens.
  2. If you hit the Home page https://johndous.com/ and then navigate to Useful links (Client side navigation) you will see some Skeleton Screens for some seconds.

I hope this helps you.

from react-skeleton-screen.

rajatjasuja23 avatar rajatjasuja23 commented on August 17, 2024

@johndous Thanks a lot...

from react-skeleton-screen.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.