Skip to content

Commit bbc2318

Browse files
committed
Add window check before initializing doc search API.
1 parent 0ec6083 commit bbc2318

File tree

1 file changed

+18
-16
lines changed
  • packages/react-renderer-demo/src/app/src/components

1 file changed

+18
-16
lines changed

packages/react-renderer-demo/src/app/src/components/docsearch.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
import React, { useEffect } from 'react';
2-
import TextField from '@material-ui/core/TextField'
3-
import InputAdornment from '@material-ui/core/InputAdornment'
2+
import TextField from '@material-ui/core/TextField';
3+
import InputAdornment from '@material-ui/core/InputAdornment';
44
import makeStyles from '@material-ui/core/styles/makeStyles';
55
import Search from '@material-ui/icons/Search';
66

77
const useStyles = makeStyles(() => ({
88
docSearchWrapper: {
99
marginRight: 16,
1010
'& .algolia-docsearch-suggestion.algolia-docsearch-suggestion__main.algolia-docsearch-suggestion__secondary': {
11-
textDecoration: 'none'
11+
textDecoration: 'none',
1212
},
1313
'& .algolia-autocomplete .algolia-docsearch-suggestion--title': {
14-
marginBottom: 0
14+
marginBottom: 0,
1515
},
1616
'& .ds-dropdown-menu': {
1717
'& [class^=ds-dataset-]': {
1818
borderRadius: 0,
1919
},
2020
'&:before': {
21-
display: 'none'
22-
}
21+
display: 'none',
22+
},
2323
},
2424
},
2525
docSearchInput: {
2626
'& input': {
27-
color: 'white'
27+
color: 'white',
2828
},
2929
'& .MuiInput-underline:hover:not(.Mui-disabled):before': {
3030
borderBottomColor: 'white',
@@ -37,19 +37,21 @@ const useStyles = makeStyles(() => ({
3737
},
3838
},
3939
docSearchIcon: {
40-
fill: 'white'
41-
}
40+
fill: 'white',
41+
},
4242
}));
4343

4444
const DocSearch = () => {
45-
const classes = useStyles()
45+
const classes = useStyles();
4646
useEffect(() => {
47-
window.docsearch({
48-
apiKey: '5e9dbd314423e38339595e183d1ae7b6',
49-
indexName: 'data-driven-forms',
50-
inputSelector: '#data-driven-forms-search',
51-
debug: false
52-
});
47+
if (window.docsearch) {
48+
window.docsearch({
49+
apiKey: '5e9dbd314423e38339595e183d1ae7b6',
50+
indexName: 'data-driven-forms',
51+
inputSelector: '#data-driven-forms-search',
52+
debug: false,
53+
});
54+
}
5355
}, []);
5456
return (
5557
<form className={ classes.docSearchWrapper }>

0 commit comments

Comments
 (0)