jkk / shinkgs

A JavaScript client for the KGS Go Server
https://shin.gokgs.com/
MIT License
267 stars 55 forks source link

Derive chat state from props [#233]. #235

Closed beejunk closed 4 years ago

beejunk commented 4 years ago

A section of the code was commented out that was responsible for updating the chatSections state depending on the incoming props. This kept all messages in the chat from displaying, since chatSections is an empty array on initial render and would never get re-computed.

The original code used a method called componentWillReceiveProps that has since be renamed to UNSAFE_componentWillReceiveProps, which is probably the reason it was commented out. This PR uses the static method getDerivedStateFromProps to adjust the chatSections state in a safe manner. It only updates the state if it detects a difference in the number of messages displayed.

This resolves issue https://github.com/jkk/shinkgs/issues/233

beejunk commented 4 years ago

Vercel deployment: https://shinkgs.ectopod.vercel.app