Understanding Redux #1 by Ohans Emmanuel

Understanding Redux #1 by Ohans Emmanuel

Author:Ohans Emmanuel
Language: eng
Format: epub
Published: 2020-10-20T00:00:00+00:00


{ text: "Hello there. U good?", is_user_msg: false }

Now, representing the messages field within the state with an object, we should have something like this:

messages: { user_id: { text, is_user_msg }, user_id_2: { text, is_user_msg } }

Notice how I’m also using an object instead of an array again. Also, we’re going to map each message to the unique key, user_id of the contact.

This is because a user can have different conversations with different contacts, and it is important to show this representation within the state object. For example, when a contact is clicked, we need to know which was clicked! How do we do this? Yes, with their user_id.

The representation above is incomplete but we’ve made a whole lot of progress! The messages field we’ve represented here assumes that each contact (represented by their unique user id) has only one message.

But, that’s not always the case. A user can have many messages sent back and forth within a conversation.

So how do we do this?

The easiest way is to have an array of messages, but instead, I’ll represent this with objects.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.