You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
At @taskworld, when we write components that communicate with the store upon mounting, we must do it in three different places: componentDidMount, componentWillUnmount, and componentDidUpdate. For example:
When the threadId changes, the old component that subscribes to the old thread is simply unmounted, and the new one with the new threadId is mounted in its place.
With that, we don’t need to handle the change in threadId anymore:
Now the MessagesContainer will be replaced instead of having props sent to it. Just what I want. However, other people reviewing my code may not understand why I need to put a key prop there.
Instead of relying on the users of MessagesContainer to specify the key prop to ensure correct subscribe/unsubscribe behavior, we can simply wrap MessagesContainer in a higher-order component which automatically adds the key to the wrapped component.
At @taskworld, when we write components that communicate with the store upon mounting, we must do it in three different places:
componentDidMount
,componentWillUnmount
, andcomponentDidUpdate
. For example:What if a component can reject prop changes?
When the
threadId
changes, the old component that subscribes to the old thread is simply unmounted, and the new one with the new threadId is mounted in its place.With that, we don’t need to handle the change in
threadId
anymore:Turns out it is possible with the special
key
prop in React:Now the
MessagesContainer
will be replaced instead of having props sent to it. Just what I want. However, other people reviewing my code may not understand why I need to put akey
prop there.Instead of relying on the users of
MessagesContainer
to specify thekey
prop to ensure correct subscribe/unsubscribe behavior, we can simply wrapMessagesContainer
in a higher-order component which automatically adds the key to the wrapped component.This is our implementation of
keyed
.And here is how to use it:
The text was updated successfully, but these errors were encountered: