@@ -116,8 +116,21 @@ const CollectionDrawerContent: React.FunctionComponent<
116116 onNoteChange,
117117 onRenameCollection,
118118} ) => {
119- const [ collectionName , setCollectionName ] = useState (
120- ( ) => toNS ( namespace ) . collection
119+ const { value : collectionName , ...nameInputProps } = useChangeOnBlur (
120+ toNS ( namespace ) . collection ,
121+ ( collectionName ) => {
122+ const trimmedName = collectionName . trim ( ) ;
123+ if ( trimmedName === toNS ( namespace ) . collection ) {
124+ return ;
125+ }
126+ if ( ! isCollectionNameValid ) {
127+ return ;
128+ }
129+ onRenameCollection (
130+ namespace ,
131+ `${ toNS ( namespace ) . database } .${ trimmedName } `
132+ ) ;
133+ }
121134 ) ;
122135
123136 const {
@@ -128,23 +141,6 @@ const CollectionDrawerContent: React.FunctionComponent<
128141 [ collectionName , namespaces , namespace ]
129142 ) ;
130143
131- useLayoutEffect ( ( ) => {
132- setCollectionName ( toNS ( namespace ) . collection ) ;
133- } , [ namespace ] ) ;
134-
135- const onBlurCollectionName = useCallback ( ( ) => {
136- const trimmedName = collectionName . trim ( ) ;
137- if ( trimmedName === toNS ( namespace ) . collection ) {
138- return ;
139- }
140-
141- if ( ! isCollectionNameValid ) {
142- return ;
143- }
144-
145- onRenameCollection ( namespace , `${ toNS ( namespace ) . database } .${ trimmedName } ` ) ;
146- } , [ collectionName , namespace , onRenameCollection , isCollectionNameValid ] ) ;
147-
148144 const noteInputProps = useChangeOnBlur ( note , ( newNote ) => {
149145 onNoteChange ( namespace , newNote ) ;
150146 } ) ;
@@ -157,12 +153,9 @@ const CollectionDrawerContent: React.FunctionComponent<
157153 label = "Name"
158154 sizeVariant = "small"
159155 value = { collectionName }
156+ { ...nameInputProps }
160157 state = { isCollectionNameValid ? undefined : 'error' }
161158 errorMessage = { collectionNameEditErrorMessage }
162- onChange = { ( e ) => {
163- setCollectionName ( e . target . value ) ;
164- } }
165- onBlur = { onBlurCollectionName }
166159 />
167160 </ DMFormFieldContainer >
168161 </ DMDrawerSection >
0 commit comments