I read here that is possible to access a prop of a Record object using dot-notation like person.Name X person.get('name'). However it isn't working to me if I try to access it using the property directly.
My code:
new Record({
id: 123,
description: 'Foo',
imgSrc: 'https://foo.co'
}))
If I try to access the property description directly like person.description it doesn't work. I should use person.get('description') rather access it directly.
What I'm doing wrong since it should let me access the property directly?
You're a using a Map, but property access using dot notation is only available on Immutable.Record. Here's the relevant section on the site: https://facebook.github.io/immutable-js/docs/#/Record
//first make a template
var MyThingie = Record({id:123, description:'Foo', imgSrc: 'https://foo.co'});
//now create records
var myRecord = new MyThingie({description:'Not the default description'});
//outputs 'Not the default description'
console.log(myRecord.description);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With