Refactor Native Module Calls

/icons/calendar.svg

Last update

Nov 15, 2024

Convert Callback-Based Native Module Calls to Synchronous Assignments

This codemod updates your React Native code to use the New Architecture's synchronous native module calls, replacing callback-based patterns for improved performance and simplicity.

Example

Before

// In the old architecture, in order to handle a response from native function calls, you needed to provide a callback, and the value returned needed to be serializable:
nativeModule.getValue((value) => {
nativeModule.doSomething(value);
});

After

// In the New Architecture, you can make synchronous calls to native functions
const value = nativeModule.getValue();
nativeModule.doSomething(value);

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now