I'm new to react and I have some trouble re-rendering a component. I have the CodeFeed component with route /code/feed?user_id=${id} which displays a list with users' posts. This list can be filter by the user_id. In case user_id is undefined, the posts of all users will be displayed.
On my navbar I have two links: Code Feed(which displays the posts for all users) and My Codes(which displays the codes for the current session user).
If an user clicks on Code Feed(/code/feed) the component will render and display the list with all users' posts, but if the user clicks right after on My Codes(/code/feed?user_id=session_user) there will remain the content from Code Feed because the component will not render again to display the new content. In order to display the new content, the component has to get the new user_id from the url, but it gets it only if the component is rendered again.
I was thinking about using the state and changing the value of id from the route. I'm using the useEffect() hook and I tried to re-render the component by passing to the second argument the id. The problem is that I don't know when it's the right time to change the value of id in order to change the state of the component so I can trigger the rendering.
Here's my component and what I tried to do so far: https://gist.github.com/dayanamdr/2ac0880aa4d5f969658a6ffede3479bb