Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

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.

  • kalluu91 Profile Picture
    32 on at
    Pass updated data back to PCF index file from react file
    We can use postMessage API to exchange data between pages.
     
     
    Cheers,
    Kim Anh
  • Verified answer
    Danish N. Profile Picture
    186 on at
    Re: Pass updated data back to PCF index file from react file

    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);

     

  • Nijos Profile Picture
    61 on at
    Re: Pass updated data back to PCF index file from react file

    Hi 

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

    Thank you @ScottDurow 

  • Nijos Profile Picture
    61 on at
    Re: Pass updated data back to PCF index file from react file

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

     

     

     

  • Verified answer
    ScottDurow Profile Picture
    1,039 on at
    Re: Pass updated data back to PCF index file from react file

    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 

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 109 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 82 Super User 2025 Season 1

#3
mmbr1606 Profile Picture

mmbr1606 71 Super User 2025 Season 1

Overall leaderboard