Comments (2)
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
- If you hit the SSR version of https://johndous.com/useful-links you will NOT see any Skeleton Screens.
- 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.
@johndous Thanks a lot...
from react-skeleton-screen.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-skeleton-screen.