exportdefaultclassArtistDetailViewextendsComponent{ state ={comments:[]}handleSend=()=>{const{ text }=this.stateconst{uid, photoURL}= firebaseAuth.currentUserconst artistCommentsRef =this.getArtistCommentsRef()var newCommentRef = artistCommentsRef.push() newCommentRef.set({ text,userPhoto: photoURL, uid
});this.setState({text:''})}getArtistCommentsRef=()=>{const{ id }=this.props.artistreturn firebaseDatabase.ref(`comments/${id}`)}handleChangeText=(text)=>this.setState({text})componentDidMount(){this.getArtistCommentsRef().on('child_added',this.addComment)this.getArtistCommentsRef().once('value',snapshot=>{let comments ={comments:[]} snapshot.forEach(comment=>{ comments.comments= comments.comments.concat(comment.val())})this.setState({comments: comments.comments})})}addComment=(data)=>{const comment = data.val()this.setState({comments:this.state.comments.concat(comment)})}componentWillUnmount(){this.getArtistCommentsRef().off('child_added',this.addComment)}render(){const artist =this.props.artistconst{ comments }=this.statereturn(<View style={styles.container}><ArtistBox artist={artist}/><CommentList comments={comments}/><View style={styles.inputContainer}><TextInput style={styles.input} value={this.state.text} placeholder="Opina sobre este artista" onChangeText={this.handleChangeText}/><TouchableOpacity onPress={this.handleSend}><Icon name="ios-send-outline" size={30} color="gray"/></TouchableOpacity></View></View>);}}
Ahora cuando entro en el detail view y regreso, al ejecutar cualquier accion que cambio el state como el like o agregar un comentario tengo el warning de “SetState can only update a mounted or mounting component…” funciona bien pero sale ese warning, que estoy haciendo mal? (Pregunta 1)
Ahora la pregunta 2:
me gustaria entender por que cuando agrego
componentDidMount(){this.getArtistCommentsRef().on('child_added',this.countComments)}```
en ArtistBox.js me deja de funcionar:
handleShareButtonPress=(name, url)=>{Share.share({message: name +' - '+ url,url: url,title:'PlatziMusic'},{dialogTitle:'Share Artist Website',excludedActivityTypes:['com.apple.UIKit.activity.PostToTwitter'],tintColor:'green'}).then(this.showShareResult).catch((error)=>this.setState({result:'error: '+ error.message}));}showShareResult=(result)=>{if(result.action===Share.sharedAction){if(result.activityType){this.setState({result:'shared with an activityType: '+ result.activityType});}else{this.setState({result:'shared'});}}elseif(result.action===Share.dismissedAction){this.setState({result:'dismissed'});}}