Skip to content

Commit 951986f

Browse files
author
Haneet Singh
committed
refactor state initialization to resolve potential identifier conflicts
1 parent 008a0b5 commit 951986f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/useEditable.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ export const useEditable = (
178178
if (!opts) opts = {};
179179

180180
const unblock = useState([])[1];
181-
const state: State = useState(() => {
182-
const state: State = {
181+
const createInitialState = (onChange: any): State => {
182+
const initialState: State = {
183183
observer: null as any,
184184
disconnected: false,
185185
onChange,
@@ -190,13 +190,14 @@ export const useEditable = (
190190
};
191191

192192
if (typeof MutationObserver !== 'undefined') {
193-
state.observer = new MutationObserver(batch => {
194-
state.queue.push(...batch);
193+
initialState.observer = new MutationObserver(mutations => {
194+
initialState.queue.push(...mutations);
195195
});
196196
}
197197

198-
return state;
199-
})[0];
198+
return initialState;
199+
};
200+
const state: State = useState(() => createInitialState(onChange))[0];
200201

201202
const edit = useMemo<Edit>(
202203
() => ({

0 commit comments

Comments
 (0)