InstagramClone icon indicating copy to clipboard operation
InstagramClone copied to clipboard

Comments and Profile not reloading

Open Elie-Bsaibes opened this issue 3 years ago • 4 comments

Hello guys! I'm facing that when I submit a comment, it doesn't appear automatically with the previous ones, I should go back to feeds then to comments so it appears. My second issue is that when I upload a picture It doesn't appear automatically on the profile, I should refresh the app or log out and re-login to see it. Can anyone help me with these issues, please? Thanks in advance!

Elie-Bsaibes avatar May 06 '21 16:05 Elie-Bsaibes

I think that's just how it is made. I have the same thing. I dont think there is a solution

codetomatot avatar May 08 '21 17:05 codetomatot

Hi!

Right now the auto reload is not implemented in the project, however it is not hard to do. Just rerun the fetch function and it should update both for the comments and profile.

SimCoderYoutube avatar May 08 '21 18:05 SimCoderYoutube

Hi!

Right now the auto reload is not implemented in the project, however it is not hard to do. Just rerun the fetch function and it should update both for the comments and profile.

Thank you Simcoder for answering! But the fetch is happening in the useEffect(), isn't it supposed to re-fetch automatically when the component is updated?

Elie-Bsaibes avatar May 09 '21 07:05 Elie-Bsaibes

My second issue is that when I upload a picture It doesn't appear automatically on the profile, I should refresh the app or log out and re-login to see it. Can anyone help me with these issues, please? Thanks in advance!

I managed to fix this by connecting redux in the save.js then binding the fetchUserPosts() to the mapDispatchProps and calling the fetchUserPosts()

import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { fetchUserPosts } from '../../redux/actions';

function Save(props){
...
}

const mapDispatchProps = (dispatch) => bindActionCreators({ fetchUserPosts }, dispatch);
export default connect(null, mapDispatchProps)(Save);

Then before you props.navigation.popToTop() you add props.fetchUserPosts() to ensure the state is updated. After we post you must also add the props.posts to your useEffect in the profile page. to ensure it updates when the posts state changes

useEffect(() => { .... }, [props.posts] )

This fixed that issue for me, I hope it can help others when they are coming across this issue.

EthanToews avatar Oct 25 '21 23:10 EthanToews