Skip to content

Commit 47e4f2a

Browse files
authored
fix: small improvements to the contentful recipe
1 parent ab89345 commit 47e4f2a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docusaurus/docs/recipes/contentful.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ import { createClient } from 'contentful';
137137

138138
App.getInitialProps = async ({Component, ctx, router}) => {
139139
// Check whether route has `cms-preview` query parameter
140-
const isPreviewingContentful = Object.hasOwnProperty.call(router.query, 'cms-preview');
140+
const isPreviewingContentful = router.query['cms-preview'] != null;
141141

142142
// Set the preview or regular host
143143
const contentfulHost = isPreviewingContentful ? 'preview.contentful.com' : 'cdn.contentful.com';
@@ -208,9 +208,9 @@ export const buildStore = (initialState, { query }) => {
208208
});
209209

210210
if (
211-
// For server-side, check wether `query` exists and has the `cms-preview` key
212-
(typeof query !== 'undefined' && Object.hasOwnProperty.call(query, 'cms-preview')) ||
213-
// For client-side, check wether `window` exist and has the `cms-preview` query parameter
211+
// For server-side, check whether `query` exists and has the `cms-preview` key
212+
query?.['cms-preview'] != null ||
213+
// For client-side, check whether `window` exists and has the `cms-preview` query parameter
214214
(typeof window !== 'undefined' && new URLSearchParams(window.location.search).has('cms-preview'))
215215
) {
216216
// In a positive case, switch the client instance to access the Preview API instead
@@ -331,7 +331,7 @@ const App = ({ Component, pageProps, rootSelector, router }) => {
331331
const [isPreviewingContentful, setIsPreviewingContentful] = useState(false);
332332

333333
// Using a useEffect hook with no dependencies guaranties that it fires only once per instance of App
334-
useEffect(() => setIsPreviewingContentful(Object.hasOwnProperty.call(router.query, 'cms-preview')), []);
334+
useEffect(() => setIsPreviewingContentful(router.query['cms-preview'] != null), []);
335335

336336
return (
337337
(...)
@@ -355,7 +355,7 @@ class App extends NextApp {
355355
const { router } = this.props;
356356

357357
this.setState({
358-
isPreviewingContentful: Object.hasOwnProperty.call(router.query, 'cms-preview');
358+
isPreviewingContentful: router.query['cms-preview'] != null,
359359
});
360360
}
361361

0 commit comments

Comments
 (0)