React Native for macOS

0.81.7 · active · verified Sun Apr 19

React Native for macOS is a Microsoft-maintained fork of the core React Native framework, extending its capabilities to build native desktop applications for Apple's macOS operating system using JavaScript and React. Currently at version 0.81.7, it closely tracks the main React Native releases, offering regular patch updates and new minor versions approximately every two months (aiming for six per year), ensuring compatibility with the broader React ecosystem. Its primary differentiator is enabling developers to leverage their existing React Native knowledge and codebase to target macOS, facilitating significant code reuse across mobile (iOS/Android) and desktop platforms. This allows for a consistent developer experience and declarative UI development, similar to building for mobile, but tailored for the macOS environment.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic React Native for macOS application with a functional component, displaying text and a button, and registering the app.

import React from 'react';
import { AppRegistry, StyleSheet, Text, View, Button } from 'react-native-macos';

const App: React.FC = () => {
  const handlePress = () => {
    console.log('Button pressed!');
    // In a real app, you might update state or navigate
  };

  return (
    <View style={styles.container}>
      <Text style={styles.welcome}>Welcome to React Native for macOS!</Text>
      <Text style={styles.instructions}>
        To get started, edit App.tsx and save to reload.
      </Text>
      <Button
        onPress={handlePress}
        title="Learn More"
        color="#841584"
        accessibilityLabel="Learn more about this app"
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('MyMacOSApp', () => App);

// To run this app:
// 1. npx @react-native-community/cli init MyMacOSApp --version 0.81.2 # Use exact minor version as react-native-macos
// 2. cd MyMacOSApp
// 3. npx react-native-macos-init
// 4. npm install # Ensure dependencies are correct
// 5. npm start # In one terminal
// 6. npx react-native run-macos # In another terminal

view raw JSON →