optimistic update for like/dislike and like count with react native, redux

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



optimistic update for like/dislike and like count with react native, redux



I am building simple video with like/dislike capability like
this



but its not working properly when like or dislike rejected because in componentDidUpdate its going to loop and I dont know what condition should I use to prevent from that.
This is my component:


class PlayingVideo extends Component
constructor(props)
super(props);
this.state =
likedThis: _.includes(this.props.video.likedBy, this.props.user_id),
likedLength: this.props.video.likedBy.length
;


componentDidUpdate(prevProps, prevState, snapshot)
if (this.props.likeVideoHasError)
this.setState(
likedThis: false,
likedLength: this.state.likedLength - 1
);

if (this.props.dislikeVideoHasError)
this.setState(
likedThis: true,
ikedLength: this.state.likedLength + 1
);



like = () => ;
dislike = () =>
if (this.props.likeVideoPending ;


const mapStateToProps = (state, ownProps) =>
return
likeVideoHasError: state.video.likeVideoHasError,
dislikeVideoHasError: state.video.dislikeVideoHasError,
likeVideoPending: state.video.likeVideoPending,
dislikeVideoPending: state.video.dislikeVideoPending
;
;

export default connect(mapStateToProps)(PlayingVideo);









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard