Skip to content
This repository has been archived by the owner on Oct 29, 2020. It is now read-only.

Commit

Permalink
Replace helmet with async version
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzesie2k committed Aug 22, 2019
1 parent cf5ae4d commit 030cb53
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[redux](https://redux.js.org/) +
[redux-saga](https://redux-saga.js.org/) +
[typescript](https://www.typescriptlang.org/) +
[react-helmet](https://github.com/nfl/react-helmet) +
[react-helmet-async](https://github.com/staylor/react-helmet-async) +
[react-scripts](https://github.com/facebook/create-react-app#readme) +
[react-router](https://reacttraining.com/react-router/) +
[connected-react-router](https://github.com/supasate/connected-react-router) +
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"@types/node": "12.7.2",
"@types/react": "16.9.2",
"@types/react-dom": "16.9.0",
"@types/react-helmet": "^5.0.9",
"@types/react-redux": "^7.1.2",
"@types/react-router": "^5.0.3",
"@types/react-router-dom": "^4.3.4",
Expand All @@ -19,7 +18,7 @@
"lodash.debounce": "^4.0.8",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-helmet": "^5.2.1",
"react-helmet-async": "^1.0.2",
"react-redux": "^7.1.0",
"react-router": "^5.0.1",
"react-router-dom": "^5.0.1",
Expand Down
7 changes: 6 additions & 1 deletion src/components/BlankLayout/BlankLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Layout } from "antd";
import * as React from "react";
import { CSSProperties, FC, useMemo } from "react";
import {Helmet} from "react-helmet-async";
import styles from "./blankLayout.module.css";

const {Content} = Layout;
Expand All @@ -10,15 +11,19 @@ interface BlankLayoutProps {
* @default 300
*/
width?: number | string;
title: string;
}

const BlankLayout: FC<BlankLayoutProps> = (props) => {
const contentStyle = useMemo((): CSSProperties => ({
maxWidth: props.width || 300,
maxWidth: props.width || 420,
}),[props.width]);

return (
<Layout className={styles.layout}>
<Helmet>
<title>{props.title}</title>
</Helmet>
<Content style={contentStyle}>
{props.children}
</Content>
Expand Down
15 changes: 15 additions & 0 deletions src/hoc/withHelmet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import * as React from "react";
import { ComponentType, FC } from "react";
import { HelmetProvider } from "react-helmet-async";

export default function <Props>(WrappedComponent: ComponentType<Props>) {
const Component: FC<Props> = (props) => (
<HelmetProvider>
<WrappedComponent {...props}/>
</HelmetProvider>
);

Component.displayName = `withHelmet(${WrappedComponent.displayName || WrappedComponent.name})`;

return Component;
}
2 changes: 2 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import withOfflineMask from "./components/OfflineMask/withOfflineMask";
import withSession from "./components/Session/withSession";
import withAntdConfig from "./hoc/withAntdConfig";
import withConnectedRouter from "./hoc/withConnectedRouter";
import withHelmet from "./hoc/withHelmet";
import withReduxProvider from "./hoc/withReduxProvider";
import * as serviceWorker from './serviceWorker';
import createStore from "./store/createStore";
Expand All @@ -24,6 +25,7 @@ const renderer: (c: ComponentType) => ReactElement = compose(
createElement,
withReduxProvider(store),
withErrorScreen,
withHelmet,
withSession,
withRouterProvider(history),
withConnectedRouter(history),
Expand Down
65 changes: 29 additions & 36 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,13 @@
"@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-transform-typescript" "^7.3.2"

"@babel/[email protected]":
version "7.3.4"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.3.4.tgz#73d12ba819e365fcf7fd152aed56d6df97d21c83"
integrity sha512-IvfvnMdSaLBateu0jfsYIpZTxAc2cKEXEMiezGGN75QcBcecDUKd3PgLAncT0oOgxKy8dd8hrJKj9MfzgfZd6g==
dependencies:
regenerator-runtime "^0.12.0"

"@babel/[email protected]", "@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.3.4", "@babel/runtime@^7.4.0", "@babel/runtime@^7.4.2", "@babel/runtime@^7.4.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.5.5.tgz#74fba56d35efbeca444091c7850ccd494fd2f132"
Expand Down Expand Up @@ -1307,13 +1314,6 @@
dependencies:
"@types/react" "*"

"@types/react-helmet@^5.0.9":
version "5.0.9"
resolved "https://registry.yarnpkg.com/@types/react-helmet/-/react-helmet-5.0.9.tgz#60ab5accce74b168ca1d274671522f6b2cf2c98f"
integrity sha512-0UVaMQk/Xvq6rFaGyepSBnRApy5RE+YH0XAXlbOBhtez5D9y1/jxKaKODofPzNnJLoLQ+sATTsWQIvrw1Dtiag==
dependencies:
"@types/react" "*"

"@types/react-redux@^7.1.2":
version "7.1.2"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.2.tgz#02303b77d87e54f327c09507cf80ee3ca3063898"
Expand Down Expand Up @@ -4068,11 +4068,6 @@ execa@^1.0.0:
signal-exit "^3.0.0"
strip-eof "^1.0.0"

exenv@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/exenv/-/exenv-1.2.2.tgz#2ae78e85d9894158670b03d47bec1f03bd91bb9d"
integrity sha1-KueOhdmJQVhnCwPUe+wfA72Ru50=

exit@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c"
Expand Down Expand Up @@ -5179,7 +5174,7 @@ internal-ip@^4.2.0:
default-gateway "^4.2.0"
ipaddr.js "^1.9.0"

invariant@^2.2.2, invariant@^2.2.4:
invariant@2.2.4, invariant@^2.2.2, invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
Expand Down Expand Up @@ -8237,7 +8232,7 @@ prompts@^2.0.1:
kleur "^3.0.3"
sisteransi "^1.0.3"

[email protected], prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.5.9, prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.7.2:
prop-types@15.7.2, prop-types@15.x, prop-types@^15.5.10, prop-types@^15.5.4, prop-types@^15.5.6, prop-types@^15.5.7, prop-types@^15.5.8, prop-types@^15.5.9, prop-types@^15.6.0, prop-types@^15.6.2, prop-types@^15.7.2:
version "15.7.2"
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
Expand Down Expand Up @@ -8889,20 +8884,21 @@ react-error-overlay@^6.0.1:
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.1.tgz#b8d3cf9bb991c02883225c48044cb3ee20413e0f"
integrity sha512-V9yoTr6MeZXPPd4nV/05eCBvGH9cGzc52FN8fs0O0TVQ3HYYf1n7EgZVtHbldRq5xU9zEzoXIITjYNIfxDDdUw==

react-fast-compare@^2.0.2:
[email protected].4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-2.0.4.tgz#e84b4d455b0fec113e0402c329352715196f81f9"
integrity sha512-suNP+J1VU1MWFKcyt7RtjiSWUjvidmQSlqu+eHslq+342xCbGTYmC0mEhPCOHxlW0CywylOC1u2DFAT+bv4dBw==

react-helmet@^5.2.1:
version "5.2.1"
resolved "https://registry.yarnpkg.com/react-helmet/-/react-helmet-5.2.1.tgz#16a7192fdd09951f8e0fe22ffccbf9bb3e591ffa"
integrity sha512-CnwD822LU8NDBnjCpZ4ySh8L6HYyngViTZLfBBb3NjtrpN8m49clH8hidHouq20I51Y6TpCTISCBbqiY5GamwA==
react-helmet-async@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/react-helmet-async/-/react-helmet-async-1.0.2.tgz#bb55dd8268f7b15aac69c6b22e2f950abda8cc44"
integrity sha512-qzzchrM/ibHuPS/60ief8jaibPunuRdeta4iBDQV+ri2SFKwOV+X2NlEpvevZOauhmHrH/I6dI4E90EPVfJBBg==
dependencies:
object-assign "^4.1.1"
prop-types "^15.5.4"
react-fast-compare "^2.0.2"
react-side-effect "^1.1.0"
"@babel/runtime" "7.3.4"
invariant "2.2.4"
prop-types "15.7.2"
react-fast-compare "2.0.4"
shallowequal "1.1.0"

react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1, react-is@^16.8.4, react-is@^16.8.6:
version "16.9.0"
Expand Down Expand Up @@ -9026,14 +9022,6 @@ [email protected]:
optionalDependencies:
fsevents "2.0.7"

react-side-effect@^1.1.0:
version "1.1.5"
resolved "https://registry.yarnpkg.com/react-side-effect/-/react-side-effect-1.1.5.tgz#f26059e50ed9c626d91d661b9f3c8bb38cd0ff2d"
integrity sha512-Z2ZJE4p/jIfvUpiUMRydEVpQRf2f8GMHczT6qLcARmX7QRb28JDBTpnM2g/i5y/p7ZDEXYGHWg0RbhikE+hJRw==
dependencies:
exenv "^1.2.1"
shallowequal "^1.0.1"

react-slick@~0.25.2:
version "0.25.2"
resolved "https://registry.yarnpkg.com/react-slick/-/react-slick-0.25.2.tgz#56331b67d47d8bcfe2dceb6acab1c8fd5bd1f6bc"
Expand Down Expand Up @@ -9175,6 +9163,11 @@ regenerator-runtime@^0.11.0:
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
integrity sha512-MguG95oij0fC3QV3URf4V2SDYGJhJnJGqvIIgdECeODCT98wSWDAJ94SSuVpYQUoTcGUIL6L4yNB7j1DFFHSBg==

regenerator-runtime@^0.12.0:
version "0.12.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.12.1.tgz#fa1a71544764c036f8c49b13a08b2594c9f8a0de"
integrity sha512-odxIc1/vDlo4iZcfXqRYFj0vpXFNoGdKMAUieAlFYO6m/nl5e9KR/beGf41z4a1FI+aQgtjhuaSlDxQ0hmkrHg==

regenerator-transform@^0.14.0:
version "0.14.1"
resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.14.1.tgz#3b2fce4e1ab7732c08f665dfdb314749c7ddd2fb"
Expand Down Expand Up @@ -9699,18 +9692,18 @@ shallow-equal@^1.0.0:
resolved "https://registry.yarnpkg.com/shallow-equal/-/shallow-equal-1.2.0.tgz#fd828d2029ff4e19569db7e19e535e94e2d1f5cc"
integrity sha512-Z21pVxR4cXsfwpMKMhCEIO1PCi5sp7KEp+CmOpBQ+E8GpHwKOw2sEzk7sgblM3d/j4z4gakoWEoPcjK0VJQogA==

[email protected], shallowequal@^1.0.1, shallowequal@^1.0.2, shallowequal@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==

shallowequal@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-0.2.2.tgz#1e32fd5bcab6ad688a4812cb0cc04efc75c7014e"
integrity sha1-HjL9W8q2rWiKSBLLDMBO/HXHAU4=
dependencies:
lodash.keys "^3.1.2"

shallowequal@^1.0.1, shallowequal@^1.0.2, shallowequal@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/shallowequal/-/shallowequal-1.1.0.tgz#188d521de95b9087404fd4dcb68b13df0ae4e7f8"
integrity sha512-y0m1JoUZSlPAjXVtPPW70aZWfIL/dSP7AFkRnniLCrK/8MDKog3TySTBmckD+RObVxH0v4Tox67+F14PdED2oQ==

shebang-command@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea"
Expand Down

0 comments on commit 030cb53

Please sign in to comment.