-
Make a
Loader
component which contains a div withid="loader"
and text inside it "Loading...". Display it each time a network request is in progress. For example on index page when fetching the posts -
On Index Page, make an initial request to
https://jsonplaceholder.typicode.com/posts
to get all the posts.
While the request is in progress, display aLoader
component.
Once the request is complete, display a list of posts inside aul
with theid="postsList"
.
Each post should be displayed as aPostPreview
component inside anli
The PostPreview component will have either have classeven
orodd
depending on the index of the post.
On index page only 10 posts should be displayed.
Assumehttps://jsonplaceholder.typicode.com/posts
returns posts in multiples of 10. By default it returns 100 posts, so display 10 buttons withid="page-${pageNumber}"
and text as page number
Ex:-id=page-1
will have text 1 inside it.
Your code should not assume that number of posts will be 100, can be 20 or 30 but always in mutiples of 10.
So show only required number of buttons -
PostPreview
component are the elements which will be used on index page, to display the title of the post which contains aNavLink
to the fullPost
page.- Post Preview Structure
- Root div should have
classname="post-preview"
- Inside
post-preview
div add h2 withclassname="post-title"
- Inside h2 with
classname="post-title"
useNavLink
component pointing to path/post/${postId}
where postId is id of the corresponding post. Example:- /post/1
The link text will be the title of the post.
https://jsonplaceholder.typicode.com/posts/:id
to get the post.
2) The returned post will have propertyuserId
which will be used to make a request tohttps://jsonplaceholder.typicode.com/users/:userId
to get the user.
3) While both the requests are in progress, display aLoader
component.
4) Once both the requests are complete, display the information in following manner-
h1
with classpost-id
and text asPost id:- {id}
-
h2
with classpost-title
and text as{post.title}
-
p
with classpost-body
and text as{post.body}
-
p
with classpost-author
and text as{user.name}
(use name property from user object) -
NavLink
to/
with text asBack to Home
which takes to Index page
- Root div should have
-
Arrange all your routes in
AppRoutes
component. Use this component incomponents/App.js
file. -
Some basic styles are already present in App.css, style as per your creativity, but dont change any classnames.