import React, { useState, useCallback } from 'react'; import { InputRegionProps } from './types'; const InputRegion: React.FC = props => { const [ text, setText ] = useState(props.text || (props.domain && ( props.chromosome + ':' + props.domain.start + '-' + props.domain.end ))); const onSubmit = useCallback( () => { const p = text.replace(/[:-]+/g, ' ').replace(/,/g, "").match(/\S+/g) || []; if (p.length === 3 && p[0].startsWith("chr")) props.onSubmit && props.onSubmit({ start: +p[1], end: +p[2] }); }, [ text ]); return ( <> setText(e.target.value)} /> ); }; export default InputRegion;