0

I followed both the documentation, and the solution found here, on SO. But the input field just wouldn't load on localhost. It does however if I just add it into an index.html file.

<script async src="https://cse.google.com/cse.js?cx=123456">
</script>
<div class="gcse-search"></div>

Does anybody know what might cause it?

Things I tried:

  1. Added it to my page as displayed above.
  2. Added the script tag separately into the head tag.
  3. Added the script as a function into the ComponentDidMount
TheGabornator
  • 523
  • 1
  • 7
  • 20
  • 1
    The accepted answer's solution works for me: https://codesandbox.io/s/react-cascading-select-forked-5nzssf?file=/src/App.js –  Jul 27 '22 at 07:10
  • I figured out, that it needs to be served statically, but I don't know why. Does anybody have an answer to that? – TheGabornator Jul 27 '22 at 07:10
  • Does this answer your question? [How to embed Google Custom Search in React App?](https://stackoverflow.com/questions/53710449/how-to-embed-google-custom-search-in-react-app) –  Jul 27 '22 at 07:32
  • Nope, I literally linked it in my question. – TheGabornator Jul 27 '22 at 09:55
  • To be honest, I don't know how the example in codesandbox should work. It's using useState as useEffect – TheGabornator Jul 27 '22 at 09:56
  • 1
    Haha, you're right! Fixed. Anyway, the "Does this answer your question?" nonsense gets added automatically when you mark as dupe and I was too lazy to edit it. The point is: I know you linked to it but the proposed solution of adding the script to does work. –  Jul 28 '22 at 09:00
  • Actually, it started working! Thank you very much! – TheGabornator Jul 28 '22 at 11:32

0 Answers0