Skip to content

Commit

Permalink
refactor state initialization to resolve potential identifier conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Haneet Singh committed Jan 23, 2025
1 parent 008a0b5 commit 951986f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/useEditable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ export const useEditable = (
if (!opts) opts = {};

const unblock = useState([])[1];
const state: State = useState(() => {
const state: State = {
const createInitialState = (onChange: any): State => {
const initialState: State = {
observer: null as any,
disconnected: false,
onChange,
Expand All @@ -190,13 +190,14 @@ export const useEditable = (
};

if (typeof MutationObserver !== 'undefined') {
state.observer = new MutationObserver(batch => {
state.queue.push(...batch);
initialState.observer = new MutationObserver(mutations => {
initialState.queue.push(...mutations);
});
}

return state;
})[0];
return initialState;
};
const state: State = useState(() => createInitialState(onChange))[0];

const edit = useMemo<Edit>(
() => ({
Expand Down

0 comments on commit 951986f

Please sign in to comment.