getApp

Requires:
@ray-js/ray≥0.5.10

Method signature
getApp()

Description

Get the application's unique App instance; the instance object is src/App.tsx

Parameters

None

Return Value

Type: AppInstance
App instance object

Referenced Types

interfaceAppInstance
PropertyTypeDescription
getData() => Record<string, unknown>Get global application data
setData(data: Record<string, unknown>) => voidSet global application data

Examples

Read and write global data

import React from 'react';
import { View, Button, getApp } from '@ray-js/ray';

export default function Demo() {
  const app = getApp();

  const handleGetGlobalData = () => {
    const globalData = app.getData();
    console.log('globalData:', globalData);
  };

  return (
    <View style={{ padding: 20 }}>
      <Button onClick={handleGetGlobalData}>
        Get global data
      </Button>
      <Button
        style={{ marginTop: 10 }}
        onClick={() => {
          app.setData({ theme: 'dark' });
        }}
      >
        Update global data
      </Button>
    </View>
  );
}