import { lampApi } from '@tuya/tuya-panel-api' ; import { useState , useRef } from 'react' ; import _ from 'lodash' ; const { getSceneData , updateVersion } = lampApi . sceneApi ; const useSceneData = ( v ) => { const currentRef = useRef < ISceneData [ ] > ( [ ] ) ; const [ currentVersion , setCurrentVersion ] = useState ( v ) ; const [ data , setData ] = useState < ISceneData [ ] > ( [ ] ) ; const renderUpdateScene = ( version ) => { updateVersion ( version ) . then ( ( flag ) => { if ( flag ) { setCurrentVersion ( version ) ; getSceneData ( version ) . then ( ( response ) => { if ( ! _ . isEqual ( currentRef . current , response ) ) { currentRef . current = response ; setData ( response ) ; } } ) . catch ( ( ) => { } ) ; } } ) . catch ( err => console . log ( err ) ) ; } ; return [ data , currentVersion , { renderUpdateScene , } , ] as const ; } ; export default useSceneData ;