Search code examples
react-native-gifted-chat

react native giftedchat can not edit message text


I want to edit a message, but it's only updated when i changed this message _id. Can someone provide me how to do it, here is my code:

const onSend = useCallback((messagesToSend = []) => {
        if(editMessage != null){
            setEditMessage()
            const m = messagesToSend[0]
            const newMessages = [...messages]
            const index = newMessages.findIndex(mes => mes._id === editMessage._id);
            console.log('index: ', index)
            if(index > -1){
                newMessages[index].text = m.text // => ***i only edit the text***
                // newMessages[index]._id = uuid.v4() => ***this working if changed _id***
                console.log('newMessages', newMessages[index]) //  => ***new message changed it's text but the bubble not change when re-render***
                LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
                setMessage(newMessages)
            }
        }else{
            setReplyMessage()
            appendMessage(messagesToSend)
        }
    })


Solution

  • ok i found problem, in MessageText the function componentShouldUpdate need modify a bit