awesome-uses/src/context/FilterContext.js

56 lines
1 KiB
JavaScript
Raw Normal View History

2020-01-07 20:23:53 +00:00
import React, { createContext, useState } from 'react';
import { useStaticQuery, graphql } from 'gatsby';
const FilterContext = createContext();
const FilterProvider = function({ children }) {
const [currentTag, setCurrentTag] = useState('all');
2020-01-08 11:44:52 +00:00
const { allTag, allCountry, allComputer, allPhone } = useStaticQuery(graphql`
2020-01-07 20:23:53 +00:00
query FilterQuery {
allTag {
nodes {
name
count
}
}
allCountry {
nodes {
count
emoji
name
}
}
2020-01-08 11:44:52 +00:00
allComputer {
nodes {
count
name
}
}
allPhone {
nodes {
count
name
}
}
2020-01-07 20:23:53 +00:00
}
`);
return (
<FilterContext.Provider
value={{
tags: allTag.nodes,
countries: allCountry.nodes,
2020-01-08 11:44:52 +00:00
computers: allComputer.nodes,
phones: allPhone.nodes,
2020-01-07 20:23:53 +00:00
currentTag,
setCurrentTag,
}}
>
{children}
</FilterContext.Provider>
);
};
export default FilterContext;
export { FilterProvider };