News List
After setting up the project. We can start building our website using ReactSDK features. Let's start with building the home page of Hacker News.
#
1. Create some newsIf you are using ReactSDK Tutorial community, there already exist some news. But if you started with your community, create some posts in the default space of your community (typically named "General").
#
2. Create NewsList ComponentCreate a new component named NewsList
and route /
to it in App.tsx
.
Now we easily use the useFeed
hook to retrieve the data from the community
and show it in out website.
note
The data retrieved from useFeed
is paginated we use simplifyPaginatedResult
to flatten them in to an array.
note
The data retrieved from useFeed
does not include the
post.createdBy
by default we have to explicitly specify it in the fields
.
Now your website will show the titles of the news.
#
3. Add infinite scrollInstall react infinite scroller. Unfortunately, the package
does not come with typings, so we have to do a little trick to ignore the types. Add typings.d.ts
to the src
folder.
Then we can use fetchNextPage
and hasNextPage
property of useFeed
to easily create an infinite scroll.
note
You can see the final result here.