Skip to content

Commit b151e93

Browse files
committed
Get rid of non-null assertion
1 parent 9f597b8 commit b151e93

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

sample/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</head>
88

99
<body>
10-
<div id="react-root"></div>
10+
<div id="root"></div>
1111
<script type="module" src="./index.tsx"></script>
1212
</body>
1313
</html>

sample/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,10 @@ import { createRoot } from 'react-dom/client';
22

33
import Sample from './Sample.js';
44

5-
createRoot(document.getElementById('react-root')!).render(<Sample />);
5+
const root = document.getElementById('root');
6+
7+
if (!root) {
8+
throw new Error('Could not find root element');
9+
}
10+
11+
createRoot(root).render(<Sample />);

test/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</head>
88

99
<body>
10-
<div id="react-root"></div>
10+
<div id="root"></div>
1111
<script type="module" src="./index.tsx"></script>
1212
</body>
1313
</html>

test/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import { createRoot } from 'react-dom/client';
33

44
import Test from './Test.js';
55

6-
createRoot(document.getElementById('react-root')!).render(
6+
const root = document.getElementById('root');
7+
8+
if (!root) {
9+
throw new Error('Could not find root element');
10+
}
11+
12+
createRoot(root).render(
713
<StrictMode>
814
<Test />
915
</StrictMode>,

0 commit comments

Comments
 (0)