Skip to content

Commit f8c4340

Browse files
authored
fix(examples): guard missing mount targets in react examples (#10226)
1 parent 81689b6 commit f8c4340

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

examples/react/basic/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,6 @@ function App() {
157157
)
158158
}
159159

160-
const rootElement = document.getElementById('root') as HTMLElement
160+
const rootElement = document.getElementById('root')
161+
if (!rootElement) throw new Error('Missing #root element')
161162
ReactDOM.createRoot(rootElement).render(<App />)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ReactDOM from 'react-dom/client'
22
import App from './App'
33

4-
const rootElement = document.getElementById('root') as HTMLElement
4+
const rootElement = document.getElementById('root')
5+
if (!rootElement) throw new Error('Missing #root element')
56
ReactDOM.createRoot(rootElement).render(<App />)

examples/react/simple/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ function Example() {
4545
)
4646
}
4747

48-
const rootElement = document.getElementById('root') as HTMLElement
48+
const rootElement = document.getElementById('root')
49+
if (!rootElement) throw new Error('Missing #root element')
4950
ReactDOM.createRoot(rootElement).render(<App />)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ReactDOM from 'react-dom/client'
22
import App from './App'
33

4-
const rootElement = document.getElementById('root') as HTMLElement
4+
const rootElement = document.getElementById('root')
5+
if (!rootElement) throw new Error('Missing #root element')
56
ReactDOM.createRoot(rootElement).render(<App />)

0 commit comments

Comments
 (0)