import * as React from 'react' ; import { PaginationModel } from '../types' ; export interface UseGoToFormConfig { model : PaginationModel ; onSubmit ? : ( event : React . FormEvent < HTMLFormElement > ) => void ; } export const useGoToForm = ( { onSubmit , model } = { } as UseGoToFormConfig ) => { const [ value , setValue ] = React . useState < number > ( ) ; React . useEffect ( ( ) => { if ( value !== undefined && model . state . currentPage !== value ) { setValue ( model . state . currentPage ) ; } } , [ model . state . currentPage ] ) ; const handleSubmit = ( event ) => { event . preventDefault ( ) ; onSubmit ?. ( event ) ; model . events . goTo ( value || 0 ) ; } ; const handleChange = ( event ) => { const formattedValue = parseInt ( event . target . value , 10 ) || 0 ; setValue ( formattedValue ) ; } ; const formProps = { onSubmit : handleSubmit , } ; const inputProps = { value , onChange : handleChange , } ; return { formProps , inputProps , } ; } ;