1 import axios from 'axios';
2 import PropTypes from 'prop-types';
3 import React, { useEffect, useState } from 'react';
4 import { Helmet } from 'react-helmet';
5 import { withTranslation } from 'react-i18next';
6 import { useParams } from 'react-router-dom';
8 import CanonicalLinks from '../common/CanonicalLinks';
9 import ErrorBoundary from '../common/ErrorBoundary';
10 import ErrorMessage from '../common/ErrorMessage';
11 import Loading from '../common/Loading';
12 import NotFound from '../pages/NotFound';
13 import Detail from '../techniques/Detail';
14 import { getLanguages, getMatchedLocale, getTranslation } from '../../helpers/Technique';
15 import i18n from '../../i18n';
17 const Technique = ({ type }) => {
18 const params = useParams();
19 const { name } = params;
21 const [error, setError] = useState(null);
22 const [loading, setLoading] = useState(true);
23 const [technique, setTechnique] = useState(null);
26 const ctrl = new AbortController();
29 .get(`/api/pages/${type}/${name}`, { signal: ctrl.signal })
33 setTechnique(response.data);
50 return <ErrorMessage error={error} />;
57 return <ErrorBoundary>
59 <title>{getTranslation(technique, 'title', i18n.language)}</title>
60 <meta name="description" content={getTranslation(technique, 'short', i18n.language)} />
63 base={`/tech/${technique.name}`}
64 lang={getMatchedLocale(technique, i18n.language)}
65 langs={getLanguages(technique)}
67 <Detail technique={technique} />
71 Technique.propTypes = {
72 type: PropTypes.string,
75 export default withTranslation()(Technique);