1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/app-desktop/gui/NoteEditor/utils/useFolder.ts

30 lines
558 B
TypeScript
Raw Normal View History

2020-09-15 15:01:07 +02:00
import { useState, useEffect } from 'react';
import Folder from '@joplin/lib/models/Folder';
2020-09-15 15:01:07 +02:00
interface HookDependencies {
folderId: string;
2020-09-15 15:01:07 +02:00
}
export default function(dependencies: HookDependencies) {
2020-09-15 15:01:07 +02:00
const { folderId } = dependencies;
const [folder, setFolder] = useState(null);
useEffect(() => {
2020-09-15 15:01:07 +02:00
let cancelled = false;
async function loadFolder() {
const f = await Folder.load(folderId);
if (cancelled) return;
setFolder(f);
}
2020-11-25 16:40:25 +02:00
void loadFolder();
2020-09-15 15:01:07 +02:00
return function() {
cancelled = true;
};
}, [folderId]);
return folder;
}