2020-09-15 15:01:07 +02:00
|
|
|
import { useState, useEffect } from 'react';
|
2021-01-22 19:41:11 +02:00
|
|
|
import Folder from '@joplin/lib/models/Folder';
|
2020-09-15 15:01:07 +02:00
|
|
|
|
|
|
|
interface HookDependencies {
|
2020-11-12 21:29:22 +02:00
|
|
|
folderId: string;
|
2020-09-15 15:01:07 +02:00
|
|
|
}
|
|
|
|
|
2020-11-12 21:13:28 +02:00
|
|
|
export default function(dependencies: HookDependencies) {
|
2020-09-15 15:01:07 +02:00
|
|
|
const { folderId } = dependencies;
|
|
|
|
const [folder, setFolder] = useState(null);
|
|
|
|
|
|
|
|
useEffect(function() {
|
|
|
|
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;
|
|
|
|
}
|