Updating Loader to use hooks

This commit is contained in:
Jeff Avallone 2019-03-26 18:33:40 -04:00
parent 461d8aa7ac
commit 8186e1cf87
3 changed files with 11 additions and 16 deletions

View File

@ -119,7 +119,7 @@ exports[`App rendering an expression 2`] = `
}" }"
/> />
<span <span
data-component="withI18nextTranslation(Loader)" data-component="Loader"
data-props="{}" data-props="{}"
/> />
</DocumentFragment> </DocumentFragment>
@ -200,7 +200,7 @@ exports[`App rendering with an invalid syntax 2`] = `
}" }"
/> />
<span <span
data-component="withI18nextTranslation(Loader)" data-component="Loader"
data-props="{}" data-props="{}"
/> />
</DocumentFragment> </DocumentFragment>

View File

@ -1,21 +1,17 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import { useTranslation } from 'react-i18next';
import { withTranslation } from 'react-i18next';
import LoaderIcon from 'react-feather/dist/icons/loader'; import LoaderIcon from 'react-feather/dist/icons/loader';
import style from './style.module.css'; import style from './style.module.css';
const Loader = ({ t }) => ( const Loader = () => {
<div className={ style.loader }> const { t } = useTranslation();
return <div className={ style.loader }>
<LoaderIcon /> <LoaderIcon />
<div className={ style.message }>{ t('Loading...') }</div> <div className={ style.message }>{ t('Loading...') }</div>
</div> </div>;
);
Loader.propTypes = {
t: PropTypes.func.isRequired
}; };
export { Loader }; export default Loader;
export default withTranslation()(Loader);

View File

@ -1,15 +1,14 @@
import React from 'react'; import React from 'react';
import { render } from 'react-testing-library'; import { render } from 'react-testing-library';
import { mockT } from 'i18n'; import Loader from 'components/Loader';
import { Loader } from 'components/Loader';
describe('Loader', () => { describe('Loader', () => {
test('rendering', () => { test('rendering', () => {
// Using full rendering here since styles for this depend on the structure // Using full rendering here since styles for this depend on the structure
// of the SVG. // of the SVG.
const { asFragment } = render( const { asFragment } = render(
<Loader t={ mockT } /> <Loader/>
); );
expect(asFragment()).toMatchSnapshot(); expect(asFragment()).toMatchSnapshot();
}); });