import { useEffect , useState } from 'react' ; import type { IConnectionsResource } from '@cloudbeaver/core-connections' ; import { useService } from '@cloudbeaver/core-di' ; import { ConnectionFormService } from './ConnectionFormService' ; import { ConnectionFormState } from './ConnectionFormState' ; import type { IConnectionFormState } from './IConnectionFormProps' ; export function useConnectionFormState ( resource , configure ? ) { const service = useService ( ConnectionFormService ) ; const [ state ] = useState < IConnectionFormState > ( ( ) => { const state = new ConnectionFormState ( service , resource ) ; configure ?. ( state ) ; state . load ( ) ; return state ; } ) ; useEffect ( ( ) => ( ) => state . dispose ( ) , [ ] ) ; return state ; }