web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Pass updated data back...
Power Apps
Unanswered

Pass updated data back to PCF index file from react file

(0) ShareShare
ReportReport
Posted on by 61

Hi,

I am using react with PCF, ReactDOM.render() method is called  from updateView() methods in index file. 

The react app(.tsx) accepts different input values and transforms it into the required format. now I need to update this processed value back to CDS(D365). Has someone done this before? I can pass the context to react app and update CDS directly using web API but, I know its not a good approach. I can update data collection as state property and access it from index file, again here I  won't get the update event happening in reach app index file. following is my update view method.

	public updateView(context: ComponentFramework.Context<IInputs>): void
	{
		
		this._props.data =context.parameters.sampleDataSet;
		ReactDOM.render(
			React.createElement(
				App,
				this._props
			),
			this.theContainer
		);
	}

  Please advise the best approach if someone has done this before.

 

Many thanks in advance.

I have the same question (0)
  • Verified answer
    ScottDurow Profile Picture
    1,039 on at

    Hi,

    Why do you think it’s not the best approach? If you need to update data that is bound to your dataset PCF control in a Model driven app then using the Xrm.WebApi is the easiest approach. https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/webapi/updaterecord

     

    You could update the data locally in your react app at the same time so you don’t need to refresh the dataset.

     
    Hope this helps 

  • Nijos Profile Picture
    61 on at

    Thank you @ScottDurow, I wanted to reconfirm if that is the best approach to go. 

     

     

     

  • Nijos Profile Picture
    61 on at

    Hi 

    I wanted to reconfirm if that is the best approach to go.

    Thank you @ScottDurow 

  • Verified answer
    Danish N. Profile Picture
    186 on at

    I like to keep my Code and UI separate (in this case MVVM design). So, I don't like to pass the context to React component. Rather, I would create a callback function as a property with parameter/s. React component will invoke this function when the value changes and pass that value to the function in form of parameters. In my code file, I will write the definition for that function.

     

    React:

    export interface IReactComponentProps {
     data: string;
     returnDataFunction?: (returnValue: string) => void;
    }
    
    export class ReactComponentSample extends React.Component<IReactComponentProps, IReactComponentState> {
    //Your UI render logic goes here and init state
    
    private localReturnDataFunction() {
     // Get your data here
     this.state.returnDataFunction(data);
    }
    
    public render() {
     return (
     <Fabric>
     <PrimaryButton text="Primary" onClick={this.localReturnDataFunction} allowDisabledFocus />
     </Fabric>
     );
    }

     

    Code file:

    // Init your React component
    
    private reactProps: IReactComponentProps {
    	data: ""
    }
    
    private actionFunction(data: string): void {
    	// Either call notifyOutputChanged or WebApi to update the data
    }
    
    // Inside updateView before rendering React component - Init properties
    reactProps.returnDataFunction = this.actionFunction.bind(this);

     

  • kalluu91 Profile Picture
    39 on at
    We can use postMessage API to exchange data between pages.
     
     
    Cheers,
    Kim Anh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard