LoginSignup
0
1

More than 5 years have passed since last update.

react-modalでUncaught TypeError: Cannot read property 'appendChild' of null

Posted at

react-modalでUncaught TypeError: Cannot read property 'appendChild' of null

Documentには...

Githubの公式Documentにはデフォルトではdocument.bodyがしていされるとのこと

/*
By default the modal is anchored to document.body. All of the following overrides are available.

* element
Modal.setAppElement(appElement);

* query selector - uses the first element found if you pass in a class.
Modal.setAppElement('#your-app-element');

*/

ただ、やってみると空でダメだった。前に使った時は特に何もせずとも動いていたので原因がわからなかった。なんとなく、DOMとjsの読み込みのタイミングの差かなと思っていろいろ調べてみたが、DOMはきちんと読み込まれているのにModal

解決策

jsxでModalの記述を行う直前に手動でdocument.bodyをセットしてあげると動いた。
ドキュメントを読むのをサボっていたのでかなり時間を食った。。。
コードを読むより、ReadMeがあるなら先にそっちをちゃんと読みましょう。。。。

Modal.setAppElement(document.body)
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1