文件
mynode/packages/app-desktop/gui/NoteEditor/utils/useEffectiveNoteId.ts
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

22 行
921 B
TypeScript

import { useEffect, useRef } from 'react';
import { NoteEditorProps } from './types';
export default function useEffectiveNoteId(props: NoteEditorProps) {
// When a notebook is changed without any selected note,
// no note is selected for a moment, and then a new note gets selected.
// In this short transient period, the last displayed note id should temporarily
// be used to prevent NoteEditor's body from being unmounted.
// See https://github.com/laurent22/joplin/issues/6416
// and https://github.com/laurent22/joplin/pull/6430 for details.
const lastDisplayedNoteId = useRef<string>(null);
const whenNoteIdIsTransientlyAbsent = !props.noteId && props.notes.length > 0;
const effectiveNoteId = whenNoteIdIsTransientlyAbsent ? lastDisplayedNoteId.current : props.noteId;
useEffect(() => {
if (props.noteId) lastDisplayedNoteId.current = props.noteId;
}, [props.noteId]);
return effectiveNoteId;
}