refactor: using react hooks

This commit is contained in:
alxshelepenok
2019-05-09 16:57:42 +03:00
parent cb4d08f434
commit 4ada925e0f
45 changed files with 1972 additions and 781 deletions

4
src/hooks/index.js Normal file
View File

@@ -0,0 +1,4 @@
// @flow
export { default as useSiteMetadata } from './use-site-metadata';
export { default as useCategoriesList } from './use-categories-list';
export { default as useTagsList } from './use-tags-list';

View File

@@ -0,0 +1,23 @@
// @flow
import { useStaticQuery, graphql } from 'gatsby';
const useCategoriesList = () => {
const { allMarkdownRemark } = useStaticQuery(
graphql`
query CategoriesListQuery {
allMarkdownRemark(
filter: { frontmatter: { template: { eq: "post" }, draft: { ne: true } } }
) {
group(field: frontmatter___category) {
fieldValue
totalCount
}
}
}
`
);
return allMarkdownRemark.group;
};
export default useCategoriesList;

View File

@@ -0,0 +1,41 @@
// @flow
import { useStaticQuery, graphql } from 'gatsby';
const useSiteMetadata = () => {
const { site } = useStaticQuery(
graphql`
query SiteMetaData {
site {
siteMetadata {
author {
name
bio
photo
contacts {
email
telegram
twitter
github
rss
vkontakte
}
}
menu {
label
path
}
url
title
subtitle
copyright
disqusShortname
}
}
}
`
);
return site.siteMetadata;
};
export default useSiteMetadata;

View File

@@ -0,0 +1,23 @@
// @flow
import { useStaticQuery, graphql } from 'gatsby';
const useTagsList = () => {
const { allMarkdownRemark } = useStaticQuery(
graphql`
query TagsListQuery {
allMarkdownRemark(
filter: { frontmatter: { template: { eq: "post" }, draft: { ne: true } } }
) {
group(field: frontmatter___tags) {
fieldValue
totalCount
}
}
}
`
);
return allMarkdownRemark.group;
};
export default useTagsList;