Edit

Share via


Power Apps client library for code apps v1.0 Migration Guide

As code apps approach general availability, we're improving the Power Apps client library for code apps and releasing version 1.0. These improvements include breaking changes from version 0.3.21.

Initialization isn't required

The Power Apps client library for code apps version 1.0 and later remove the initialize function. Apps must no longer import or call initialize. You can now make data calls, retrieve context, and interact with the platform directly without waiting on Power Apps client library for code apps initialization.

Changes required

Review and apply the following changes to migrate existing code apps from Power Apps client library for code apps v0.3.21 to v1.0.

Remove imports of initialize function

Remove code like the following import statement, which is typically found at the top of your file.

import { initialize } from '@microsoft/power-apps

Remove logic that waits on client library initialization events

Remove code like the following example that invokes the initialize function and sets initialization state flags.

useEffect(() => {
// Define an async function to initialize the Power Apps client library for code apps
const init = async () => {
      try {
            await initialize(); // Wait for client library initialization
            setIsInitialized(true); // Mark the app as ready for data operations
      } catch (err) {
            setError('Failed to initialize Power Apps client library for code apps'); // Handle initialization errors
            setLoading(false); // Stop any loading indicators
      }
};

init(); // Call the initialization function when the component mounts
}, []);

useEffect(() => {
// Prevent data operations until the client library is fully initialized
if (!isInitialized) return;

// Place your data reading logic here
}, []);

Remove initialization state flags

Remove code that checks initialization state flags, such as isInitialized, before using client library methods.

New setConfig API

A new setConfig API is available from @microsoft/power-apps/app. By using this API, apps can opt in to optional behaviors and observability features.

Supported config options include:

Logger: Supply a logger with a logMetric function. This logMetric function logs session and network metrics to the telemetry or monitoring service of your choice. For more information, see How to: Set up Azure App Insights for your code app.