From 702b4fd6bda086428e0773c3fe7fdac5a714bbf7 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Wed, 17 Apr 2024 12:07:24 +0200 Subject: [PATCH] Get rid of non-null assertion --- sample/index.html | 2 +- sample/index.tsx | 8 +++++++- test/index.html | 2 +- test/index.tsx | 8 +++++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/sample/index.html b/sample/index.html index 3eb045f..71425bb 100644 --- a/sample/index.html +++ b/sample/index.html @@ -7,7 +7,7 @@ -
+
diff --git a/sample/index.tsx b/sample/index.tsx index e9d4869..3c8d66c 100644 --- a/sample/index.tsx +++ b/sample/index.tsx @@ -2,4 +2,10 @@ import { createRoot } from 'react-dom/client'; import Sample from './Sample.js'; -createRoot(document.getElementById('react-root')!).render(); +const root = document.getElementById('root'); + +if (!root) { + throw new Error('Could not find root element'); +} + +createRoot(root).render(); diff --git a/test/index.html b/test/index.html index 184b406..b96f594 100644 --- a/test/index.html +++ b/test/index.html @@ -7,7 +7,7 @@ -
+
diff --git a/test/index.tsx b/test/index.tsx index caf8bfe..fabd14f 100644 --- a/test/index.tsx +++ b/test/index.tsx @@ -3,7 +3,13 @@ import { createRoot } from 'react-dom/client'; import Test from './Test.js'; -createRoot(document.getElementById('react-root')!).render( +const root = document.getElementById('root'); + +if (!root) { + throw new Error('Could not find root element'); +} + +createRoot(root).render( ,