Pluggable widget props visibility

0
I am creating a React ‘pluggable widget’ in Mendix 8.  I am passing a context object as props to the widget, however I need to do some initialisation (which would normally be done in the lifecycle method componentDidMount). The thing is, all the props seem to be undefined in this function. I.e: export class Test extends Component { componentDidMount() { const { apiHost } = this.props; console.warn(apiHost.value) // prints undefined } render() { console.warn(this.props.apiHost.value) // prints the proper value return <div>Test</div> } } How can I access the value within componentDidMount? 
asked
3 answers
4

I found the answer. Each prop is an object with a ‘status’ property, which will eventually be set to ‘visible'.

So the best place for initialisation based on props (e.g. contacting a remote server) is probably in componentDidUpdate rather than componentDidMount, checking the value of ‘status’ before doing work….

It would be good if stuff like this was documented – the ‘pluggable widget’ documentation is incredibly thin….

answered
1

Perhaps you could do this with async and await. This way the function would await result

https://www.valentinog.com/blog/await-react/

async componentDidMount() {
  const response = await fetch('link');
  const json = await response.json();
  this.setState({ data: json });
}

 

answered
0

Hi James,

The typings are found in https://www.npmjs.com/package/mendix

There is you can find the hint on the API 

there .status in the attribute, that can have a value: loading, unavailable, available

Reference documentation is on its way, we plan to ship when Mx8 GA is released. For now there is only the how to https://docs.mendix.com/howto/extensibility/pluggable-widgets

Cheers, Andries

 

answered