lodash-es#defaults TypeScript Examples
The following examples show how to use
lodash-es#defaults.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: use-preview.ts From bext with MIT License | 6 votes |
usePreview = (disableDraft: boolean = false /* 不可变 */) => {
const [{ previewId, previewMeta }] = useUrlState({
previewMeta: undefined,
previewId: undefined,
});
const { draft } = disableDraft ? { draft: null } : useDraft();
const getPreviewMeta = useCallback<() => Promise<Meta>>(async () => {
switch (previewMeta) {
case 'draft':
return defaults(cloneDeep(draft), {
id: previewId,
version: '请填写版本',
name: '请填写脚本名称',
tags: [],
synopsis: '请填写脚本简介',
detail: '请填写脚本详情',
type: 'javascript',
source: '',
});
default:
const response = await fetch(previewMeta);
return Object.assign({}, await response.json(), {
id: String(previewId),
});
}
}, [previewMeta, previewId, draft]);
return {
previewId,
previewMeta,
getPreviewMeta,
};
}