In your top level React component, make sure to check on the status of the datasource and only if available feed the datasource to the actual display component:
if (!datasource || datasource.status !== ValueStatus.Available || !datasource.items) {
return <div>Loading data...</div>;
}
return (
<div>
<SomeContainer
someAttr={this.props.someAttr}
mxObjects={datasource.items}
/>
</div>
);
In your display component iterate over your mxObjects and get the actual values of its attributes via something like below:
const mxObjects: ObjectItem[] = this.props.mxObjects;
if (mxObjects) {
// eslint-disable-next-line array-callback-return
props.mxObjects.map(mxObject => {
const someAttrValue = Number(this.props.someAttr(mxObject).value);
});
}
You could check out my Google Maps Custom Marker widget available in the Marketplace based on React to see how this is implemented!
EDIT: the definition for some attribute, which is connected to the datasource, is covered within the widget XML. It is key set the datasource attribute of this datasource:
<property key="datasource" type="datasource" isList="true" required="false">
<caption>Data source objects</caption>
<description>Dynamically load a data source of Mendix objects into the widget.</description>
</property>
<property key="someAttr" type="attribute" required="false" dataSource="datasource">
<caption>Some attribute</caption>
<description>The attribute of the data source.</description>
<attributeTypes>
<attributeType name="String"/>
</attributeTypes>
</property>