Reputation: 21
I'm having trouble with an object that I need to pass a variable in so it's passing a string
this.context.updateCurrentValues({ "`${this.state.path}`": maskedvalue})
should be passed on like this:
this.context.updateCurrentValues({ "prices.2.price": maskedvalue})
I believe there is an error in the string concatenation, remembering that I need to pass an object to the function
Can someone help me?
Upvotes: 0
Views: 133
Reputation: 624
EDIT:
To have the string you need, you don't want to use the double quote. But if you don't use the quotes, you will have an error. So you need to create your object step by step:
var myObject = {};
myObject[`${this.state.path}`] = maskedvalue;
this.context.updateCurrentValues(myObject);
=============================
Old answer:
You don't need the double quotes:
this.context.updateCurrentValues({ `${this.state.path}`: maskedvalue})
Upvotes: 1
Reputation: 8972
You forgot the []
. This should work:
this.context.updateCurrentValues({ ["prices.2.price"]: maskedvalue});
Upvotes: 0