Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

how to use typescript on createRoot

// Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Element | DocumentFragment'.
// Type 'null' is not assignable to type 'Element | DocumentFragment'.ts(2345)

// typescript error on createRoot (React 18)

// const root = ReactDOM.createRoot(document.getElementById("root"))


--- add non-null assertion

const root = ReactDOM.createRoot(document.getElementById("root")!)


 
PREVIOUS NEXT
Tagged: #typescript #createRoot
ADD COMMENT
Topic
Name
5+6 =