1. Home
  2. Docs
  3. TikTok App Template
  4. Exploring the Codebase
  5. Hashtags

Hashtags

When composing a new post with an hashtag, you will need to extract all hashtags from this new post. This is done in the file “src/screens/NewPostScreen/NewPostScreen.js” in the method that can be found in line 55  with the name “findHastags”.  We called this method in line 72. 

const onShare = () => {
  setLoading(true);
  const hashtags = findHashtags(newPost.current.postText);


In the method findHashtag, we have used a regular expression to extract hashtags from the caption of a new post. The findHastags method returns and array of hashtags found in the caption of this new post.

We have stored the array of hashtags in hashtags field in the new post object in line 76. This new post object also contain fields like “authorID” and “postMedia”.

authorID: currentUser.id,
hashtags,
postMedia: media,

Still in NewPostScreen.js file, In line 94, you will find postAPIManager?.addPost”.  This method is called with postToUpload object which is an object with the necessary details of the post to upload including fields like hashtags.

};
await postAPIManager?.addPost(
  postToUpload,

The method “postAPIManager?.addPost” is defined in the path to the file “src/Core/socialGraph/feed/api/firebase/post.js”. Here, in line 371,  you will find the definition of the addPost function. In this function, at line 405  you will find how each hashtags is saved in the Firebase firestore document.

finalPost.hashtags.forEach((hashtag) => {
  const hashtagRef = firebase
    .firestore()
    .collection('entities')
    .doc('social_feeds_hashtags')
    .collection(hashtag)
    .doc(finalPost.id);

Reading and displaying hashtags in Discover Screen
Navigate to path “src/screens/DiscoverScreen/DiscoverScreen.js”. Here, you will find the file that displays the discover screen.  We have the discover post at line 17 with the name discoverFeedPosts. 

const discoverFeedPosts = useSelector(
  (state) => state.feed.discoverFeedPosts,
);

At line 93,  we have passed this discoverFeedPosts to the method filterOutRelatedPosts  that filters out related discover posts.
In this filterOutRelatedPosts method, at line 59, we have returned a method with the name groupByHashTags  that takes the filteredPosts array.

This groupByHashTags  simply groups the filteredPosts by hashtags and returned an array of grouped hashtags posts in this format:

{ hashtag: hashtag, videos: [filteredPost] }