import React from 'react' ; import type { App , Connector , CallbackType } from 'rallie' ; export function stateHook < State extends object > ( app ) { return function < P = any > ( getter ) { const [ value , setValue ] = React . useState < P > ( getter ( app . state ) ) ; React . useEffect ( ( ) => { const unwatch = app . watchState ( getter ) . do ( ( val ) => { setValue ( val ) ; } ) ; return ( ) => { unwatch ( ) ; } ; } , [ getter ] ) ; return value ; } ; } export function eventsHook < Events extends Record < string , CallbackType > > ( app ) { return function ( events ) { React . useEffect ( ( ) => { const off = app . listenEvents ( events ) ; return ( ) => { off ( ) ; } ; } , [ events ] ) ; } ; } export function methodsHook < Methods extends Record < string , CallbackType > > ( app ) { return function ( events ) { React . useEffect ( ( ) => { const off = app . addMethods ( events ) ; return ( ) => { off ( ) ; } ; } , [ events ] ) ; } ; }