diff --git a/libs/components/editor-core/src/recast-block/view.ts b/libs/components/editor-core/src/recast-block/view.ts index 64f44eda7d..e26b38bb32 100644 --- a/libs/components/editor-core/src/recast-block/view.ts +++ b/libs/components/editor-core/src/recast-block/view.ts @@ -77,10 +77,9 @@ export const useRecastView = () => { const addView = useCallback( async (newView: RecastViewWithoutId) => { - await setViews([ - ...recastViews, - { ...newView, id: genViewId() } as RecastView, - ]); + const newViewWithId = { ...newView, id: genViewId() } as RecastView; + await setViews([...recastViews, newViewWithId]); + return newViewWithId; }, [recastViews, setViews] ); @@ -88,7 +87,7 @@ export const useRecastView = () => { const updateView = useCallback( async (newView: RecastView) => { const idx = recastViews.findIndex(v => v.id === newView.id); - if (!idx) { + if (idx === -1) { throw new Error('Failed to find view with id ' + newView.id); } await setViews([ @@ -141,7 +140,7 @@ export const useRecastView = () => { recastViews, setCurrentView, addView, - // updateView, + updateView, renameView, removeView, // TODO reorder API