Skip to content

frontend / features/NewProject/useNewProject / useNewProject

Function: useNewProject() ​

useNewProject(onCleared?): object

Defined in: features/NewProject/useNewProject.ts:34

Hook which provides "create new project" action.

Before clearing workspace, asks user for confirmation via window.confirm. This is important because unsaved changes cannot be restored — there is no undo for full workspace reset.

After confirmation:

  1. clears workspace,
  2. creates fresh start_block,
  3. clears undo history so user cannot accidentally undo back to old project.

Order matters: clear() before createStartBlock(), otherwise new start block would be removed together with old content. And clearUndo() after everything else, so it wipes the whole reset as one atomic step.

Parameters ​

onCleared? ​

() => void

Optional callback which runs after workspace is reset. Useful to clear other state (code preview, output, debug variables) which lives outside of workspace.

Returns ​

object

Object with single createNewProject() method.

createNewProject ​

createNewProject: () => void

Returns ​

void

Example ​

tsx
const { createNewProject } = useNewProject(() => {
    setCode({ toLaunch: '', toShow: '' });
});