PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 0.7.0 All 126 releases
extendify / src / HelpCenter / hooks / useSupportArticles.js

useSupportArticles.js in Extendify 2.2.0, at src/HelpCenter/hooks/useSupportArticles.js

20 lines 604 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { KB_HOST } from '@constants';
2 import useSWRImmutable from 'swr/immutable';
3
4 export const fetcher = (slug) => {
5 const lang = window.extSharedData.wpLanguage || null;
6 const params = new URLSearchParams({ lang });
7 return fetch(`${KB_HOST}/api/posts/${slug}?${params.toString()}`).then(
8 (res) => {
9 if (res.status === 404) throw new Error('Not found');
10 if (!res.ok) throw new Error(res.statusText);
11 return res.json();
12 },
13 );
14 };
15
16 export const useSupportArticle = (slug) => {
17 const { data, error } = useSWRImmutable(slug, fetcher);
18 return { data, error, loading: !data && !error };
19 };
20