getCustomConfig

Requires:
Base library≥2.0.0@ray-js/ray≥1.7.29
import { getCustomConfig } from '@ray-js/ray';

// Promise usage
try {
  const res = await getCustomConfig();
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

Description

Retrieve custom Mini Program configuration. This API fetches custom business configuration defined in the Developer Console, supporting multiple data types (URL, boolean, number, string). Custom configuration supports hierarchical management with template-level and instance-level settings; instance settings take precedence over template settings. Changes are automatically synced to the cloud, and the Mini Program can use this API to obtain the latest configuration.

Parameters

Overload 1getCustomConfig(options: Object)→void
PropertyTypeRequiredDescription
NoCallback invoked when the API call succeeds; the argument is a key-value map of configuration items.
NoFailure callback
NoCompletion callback (executed on both success and failure)
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestringError code
Error extension
Overload 2getCustomConfig()→Promise<Record<string, string | number | boolean | string>>

None

Return Value

Type: void | Promise<Record<string, string | number | boolean | string>>
Returns a Promise when no callback is provided; the resolved value is an object of custom configuration key-value pairs

Error Code

Error CodeError Message
7API internal processing failed

Referenced Types

typeCustomConfigValueValue types for custom configuration items; supports string, number, and boolean
export type CustomConfigValue =
  /** 字符串 */
  | string
  /** 数字 */
  | number
  /** 布尔值 */
  | boolean
  /** 链接(特殊字符串) */
  | string;

Examples

Callback mode

import { View, Button, Text, getCustomConfig } from '@ray-js/ray'

export default function Demo() {
  const handleGetConfig = () => {
    getCustomConfig({
      success(config) {
        console.log('Custom config:', config);
      },
      fail(err) {
        console.error('Failed to get:', err.errorMsg);
      },
    });
  };

  return (
    <View style={{ padding: 20 }}>
      <Button onClick={handleGetConfig}>Get custom config (callback)</Button>
    </View>
  );
}

Promise mode

import { View, Button, Text, getCustomConfig } from '@ray-js/ray'

export default function Demo() {
  const [config, setConfig] = useState('');

  const handleGetConfig = async () => {
    try {
      const result = await getCustomConfig();
      setConfig(JSON.stringify(result));
      console.log('Custom config:', result);
    } catch (err) {
      console.error('Failed to get:', err);
    }
  };

  return (
    <View style={{ padding: 20 }}>
      <Button onClick={handleGetConfig}>Get custom config (Promise)</Button>
      {config && <Text style={{ marginTop: 10 }}>{config}</Text>}
    </View>
  );
}