Dynamics - React Glue Components
Dynamics - React Glue Components
We saw the use of runAfterSave
as a function that set the entity id and entityname on our components using method calls. This approach is not very react oriented which is much more about state being passed down as props from the parent component. While redux and other toolkits suggest injecting state directly into the component is Ok, e.g. an observable changes and the props on a component changes, we can do something a bit simpler.
We'll leave it as an exercise on how to change the runAfterSave
into an observable. Here, we will create a simple parent component that passes down entityId and entityName to a single child component when values are available. We'll also create a simple component that provides the Xrm context as a context that any sub-component can access directly.
Dynamics Wrapper
Much like the redux wrapper that provides a store to child components, we can provide Xrm as part of a context. This allows components to use a consistent approach to obtaining Xrm when needed.
The use of default types in Dynamics allows this to be properly extended or used directly without specifying the property type. Your class could subclass this, but its better to be used as a container. You could also use recompose to make this into something composable using just a function.
You would use this like:
Then just to access the context within YourComponent, declare the context types as per the react manual setting the type DynamicsContext. Then:
The notifier can be used simply as well:
Passing EntityId and EntityName Component
We can easily extend Dynamics to include entityid logic and use this when we are working with entities:
Your component would just use the standard componentWillReceiveProps
to nab the new "entityId" state on its change, for example if you are on a "create" form and the entity is saved, we need to have the "entity" be consumed.
Simple Notifier
We mentioned the notifier above. Since we have a react component, we can maintain the state of a notification in our component state then remove the message after a certain time...or do other tricks.
...
Last updated
Was this helpful?