Adding a HOC for using StaticQuery

This commit is contained in:
Jeff Avallone
2019-01-06 13:56:25 -05:00
parent bf35f26d5b
commit 3b11fcb0b6
8 changed files with 57 additions and 57 deletions
@@ -4,13 +4,7 @@ exports[`Footer rendering 1`] = `
ShallowWrapper {
Symbol(enzyme.__root__): [Circular],
Symbol(enzyme.__unrendered__): <Footer
site={
Object {
"siteMetadata": Object {
"buildId": "abc-123",
},
}
}
buildId="abc-123"
t={[Function]}
/>,
Symbol(enzyme.__renderer__): Object {
+12 -13
View File
@@ -1,8 +1,10 @@
import React from 'react';
import PropTypes from 'prop-types';
import { StaticQuery, graphql } from 'gatsby';
import { graphql } from 'gatsby';
import { withNamespaces, Trans } from 'react-i18next';
import withQuery from 'lib/with-query';
import style from './style.module.css';
const query = graphql`
@@ -15,7 +17,7 @@ const query = graphql`
}
`;
export const Footer = ({ t, site: { siteMetadata } }) => (
export const Footer = ({ t, buildId }) => (
<footer className={ style.footer }>
<ul className={ style.list }>
<li>
@@ -33,22 +35,19 @@ export const Footer = ({ t, site: { siteMetadata } }) => (
</li>
</ul>
<div className={ style.buildId }>
{ siteMetadata.buildId }
{ buildId }
</div>
</footer>
);
Footer.propTypes = {
t: PropTypes.func.isRequired,
site: PropTypes.shape({
siteMetadata: PropTypes.shape({
buildId: PropTypes.string.isRequired
}).isRequired
}).isRequired
buildId: PropTypes.string.isRequired
};
export default withNamespaces()(props => (
<StaticQuery query={ query } render={ data => (
<Footer { ...props } { ...data } />
) } />
));
export default [
withQuery(query, {
toProps: ({ site: { siteMetadata } }) => siteMetadata
}),
withNamespaces()
].reduce((component, fn) => fn(component), Footer);
+1 -1
View File
@@ -7,7 +7,7 @@ import { Footer } from 'components/Footer';
describe('Footer', () => {
test('rendering', () => {
const component = shallow(
<Footer site={{ siteMetadata: { buildId: 'abc-123' } }} t={ mockT } />
<Footer buildId="abc-123" t={ mockT } />
);
expect(component).toMatchSnapshot();
});