render div using react in typescript

Rendering a div element using React in TypeScript is similar to how it's done in JavaScript. We can use the JSX syntax to define our HTML elements and then use the React render function to render them to the DOM.

Here's an example TypeScript code snippet that renders a div with a "Hello World" message:

import * as React from "react";
import * as ReactDOM from "react-dom";

const App = () => {
  return <div>Hello World</div>;
};

ReactDOM.render(<App />, document.getElementById("root"));
188 chars
9 lines

In this example, we define a <div> element with the message "Hello World" inside the App component using the JSX syntax. We then use the ReactDOM.render function to render the App component to an HTML element with an ID of "root".

Note that we also import the React and ReactDOM libraries at the top of our file to use their functions and types.

gistlibby LogSnag