import { DpValue } from '../../types'; import { GetSmartDeviceModelProps, ReadonlyDpSchemaList } from '../types/SdmModel'; /** * 获取智能设备功能点状态,功能点变动时驱动组件重新渲染 * @public * @since @ray-js/panel-sdk 1.2.0 * @param selector - 选择器函数,入参为当前设备环境下的全量功能点状态。 * 具体属性由 devices/schema.ts 中的 as const Schema 定义推导, * 类型映射规则:bool → boolean, value/bitmap → number, enum/string/raw → string,详见示例代码 * @typeOverride selector (props: DpState) => DpValue; * @param equalityFn - 自定义比较函数,返回 true 则不触发重渲染 * @typeOverride equalityFn (prevDpValue: DpValue, nextDpValue: DpValue) => boolean * @returns 通过 selector 选择器选择后返回的功能点值,类型基于业务项目提供的 Schema 定义,按 property.type 自动推导值类型 * @typeOverride returns DpValue * @remarks * 基于 sdm 实例实现。必须在 SdmProvider 内部使用。 * 使用前请注意检查项目是否已挂载了 SdmProvider,项目接入可参考 [智能设备模型 - 使用](/cn/miniapp/solution-panel/ability/common/sdm/usage),全新项目可直接基于 [public-sdm](https://github.com/Tuya-Community/tuya-ray-materials/tree/main/template/PublicSdmTemplate) 示例项目进行开发。 * @example 基础用法 * ```tsx * // 1. devices/schema.ts — as const 是类型推导的基石,基于业务项目提供的 Schema 定义,按 property.type 自动推导值类型 * export const schema = [ * { code: 'switch_led', property: { type: 'bool' }, type: 'obj', mode: 'rw', id: 1, name: 'Switch' }, * { code: 'work_mode', property: { type: 'enum', range: ['white', 'colour'] }, type: 'obj', mode: 'rw', id: 2, name: 'Mode' }, * { code: 'brightness', property: { type: 'value', min: 10, max: 1000, step: 1 }, type: 'obj', mode: 'rw', id: 3, name: 'Brightness' }, * { code: 'fault', property: { type: 'bitmap', maxlen: 8 }, type: 'obj', mode: 'ro', id: 4, name: 'Fault' }, * { code: 'colour_data', property: { type: 'string', maxlen: 14 }, type: 'obj', mode: 'rw', id: 5, name: 'Colour' }, * ] as const; * * // 2. useProps — 按 property.type 自动推导值类型 * import { useProps } from '@ray-js/panel-sdk'; * * const power = useProps(dpState => dpState.switch_led); // → boolean * const mode = useProps(dpState => dpState.work_mode); // → string * const bright = useProps(dpState => dpState.brightness); // → number * const fault = useProps(dpState => dpState.fault); // → number * const colour = useProps(dpState => dpState.colour_data); // → string * ``` * @example 自定义 rerender * ```tsx * // 不传 selector 返回全量状态,则任意功能点变化都触发重渲染 * const dpState = useProps( * dpState => dpState, * (prevDpValue, nextDpValue) => prevDpValue.switch_led === nextDpValue.switch_led, // 只会在返回 false 时 rerender * ); * ``` * * @example 获取所有功能点状态 * ```tsx * // 除非当前页面或组件需要监听所有功能点的变化,否则请勿使用该方式,会导致当前页面或组件出现性能问题,频繁进行无效的重复渲染。 * import { useProps } from '@ray-js/panel-sdk'; * * const dpState1 = useProps(); * const dpState2 = useProps(props => props); * ``` */ export declare function useProps(selector?: (props: GetSmartDeviceModelProps) => V, equalityFn?: (a: V, b: V) => boolean): V;