chatscope / use-chat

React hook for state management in chat applications.
https://chatscope.io
MIT License
147 stars 23 forks source link

MessageGroup.replaceMessage does not work as expected #13

Closed victorchapado closed 2 years ago

victorchapado commented 2 years ago

Hi! There is an error with the implementation of MessageGroup.replaceMessage. Right now, the first condition always returns false because the length of the array of messages is always greater than the index that we need to replace. Besides that, the concatenation preserves the original messages array so, this one increases each time that this method is called.

My code suggestion:

replaceMessage(message, index) { 
  if (this.messages.length <= index) {
    return false;
  }

  this.messages = this.messages.slice(0, index)
    .concat(message)
    .concat(this.messages.slice(index + 1));

  return true;
}
supersnager commented 2 years ago

:tada: This issue has been resolved in version 2.0.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

supersnager commented 2 years ago

@victorchapado Thank you for the report!