Skip to content

Conversation

@Appilistus
Copy link

return saved ? JSON.parse(saved) : []
})

// fetch messages from API + interval polling

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe would be good to add some error handling in the fetch function, i.e. so that an error message is thrown if the API fetch has errors or fails!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! Thanks for the advise!

return () => clearInterval(intervalID)
},[])

// Update local storage when likedPosts changes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work with liked posts and local storage, works great!


fetchMessages() // Initial fetch

// Set interval to fetch messages every 30 seconds

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if i's maybe more efficient to use a state as dependency here (in the useEffect where you have the fetch function), instead of re-fetching every 30 seconds. In other words, so that it only re-fetches when it needs to, for example when there is an update which would be after you send a new message or like.

...But the it's maybe hard to know when there has been an update coming from someone posting from another app to the API :D. Well, just some reflections!

localStorage.setItem("likedPosts", JSON.stringify(likedPosts))
}, [likedPosts])

// Post new message to API

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you are using different API methods (async/await vs .then) between fetching the data, posting messages and likes? Just curious! :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, just for practice:)

src/App.jsx Outdated
<p>Loading Happy Thoughts...</p>
</LoadingWrapper>
) : (
<ScrollArea>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice with the scroll function for the messages!

Copy link

@gabriellaberko gabriellaberko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall really great work with this project! Looks super nice and works as expected, including some stretch goal functionality.

Nice feature with the adding the liked posts to local storage, the scroll function, as well as the use of theme. Also nice to see that you used some TypeScript in the project too! Well done!

@Appilistus
Copy link
Author

Thank you so much for your positive feed back!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants