0

I am using react-redux and am trying to access an object's key value. Initially "isBookmarked" value is false and after onClick using actions and then reducers it has been set to true.

Finally I am trying to console log the value as so:

{console.log("data[19].isBookmarked", data[19].isBookmarked)}
{console.log("data[19]", data[19])}

Responses differ although this is the same object:

see console.log response here

These lines are sequential - they have nothing else between them and they execute one after the other.

I also tried console.log'ing via accessing key value as so - data[19]["isBookmarked"], but same response.

Here is the object i'm talking about as

{
      "id": 1373,
      "isBookmarked": true,
      "category": {
        "id": 5457
      },
      "owner": {
        "id": 63
      },
      "publishDate": "2017-07-25T12:11:13+03:00",
      "views": 0,
      "texts": [
        {
          "id": 1371,
          "text": "Lorem ipsum dolor sit amet",
          "languageCode": "en"
        }
      ],
      "files": []
}
RudolphTheCat
  • 106
  • 12
  • 1
    first you're logging out the objects' property named "isBookmarked" and then you're logging out the whole object.. so what exactly is your question here? – VF_ Aug 16 '17 at 12:33
  • @VF_ when i log out the whole object, the value is **true**, but when i log out the key value - it is **false** – RudolphTheCat Aug 16 '17 at 12:35
  • this has nothing to do with react. – abdul Aug 16 '17 at 12:41
  • when you're logging data[19].isBookmarked, you have the value at this given time, when you're logging the whole object, and it changed afterward, you have the value that will change because you're logging the reference. I'm pretty sure you're logging before mutating your object. And as @abdul said, it's a simple javascript problem – Nevosis Aug 16 '17 at 12:41
  • Look at this post please : https://stackoverflow.com/questions/7389069/how-can-i-change-the-default-behavior-of-console-log-in-safari – Nevosis Aug 16 '17 at 12:43
  • @Nevosis this is not true - these both logs are two concurrent lines of code and nothing is being mutated at that time: http://imgur.com/I4upHY9 – RudolphTheCat Aug 16 '17 at 12:47
  • 1
    it is mutated right after, and in the second case you're logging the reference. Look at the little "i" in your chrome console and you'll get what I say. – Nevosis Aug 16 '17 at 13:01

0 Answers0