getAssetHostname()

Requires:
@ray-js/ray≥0.5.10

Description

Automatically obtains the static resource URL based on the App environment of the current panel

Parameters

None

Return Value

Type: Promise<string>
Static resource URL string, such as https://images.tuyacn.com

Examples

Basic usage

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

export default function Demo() {
  const [hostname, setHostname] = useState('');

  const handleGetHostname = async () => {
    try {
      const result = await getAssetHostname();
      setHostname(result);
      console.log('Static asset hostname:', result);
    } catch (err) {
      console.error('Failed to get:', err);
    }
  };

  return (
    <View style={{ padding: 20 }}>
      <Button onClick={handleGetHostname}>Get static asset hostname</Button>
      {hostname && <Text style={{ marginTop: 10 }}>{hostname}</Text>}
    </View>
  );
}