Parth Mewara
Parth Mewara

Reputation: 11

Why is my console.log in LWC showing variable data in proxy handler

I'm trying to console.log a variable's value but on the browser console instead of printing the variable (an object in my case), I am getting a Proxy container with format like Proxy {}[[Handler]]: En[[Target]]: Array(0)[[IsRevoked]]: false

On opening the [[Handler]], I get some inner properties which contains an originalTarget property. On expanding the originalTarget , my data is shown.

How do I get this data to show properly in console and also access it in my LWC ?

this.variableName returns value in a Proxy

Upvotes: 0

Views: 3099

Answers (2)

Rajat Jaiswal
Rajat Jaiswal

Reputation: 76

If you want to view proxy data so use this :

JSON.stringify(this.caseList)

And further if you want to use it in your lwc use this:

let cases = JSON.parse(JSON.stringify(this.caseList))
console.log(cases);

I hope you find the above solution helpful. If it does, please mark it as Best Answer to help others too.

Upvotes: 1

LoneWolf
LoneWolf

Reputation: 141

Reason : whenever we mark any Javascript object as @track, Salesforce wraps the object inside creating proxy objects.

Solution: @Rajat Jaiswal answer.

Upvotes: -1

Related Questions