Property ‘div’ does not exist on type ‘jsx.intrinsicelements’

To address the error you mentioned, “property ‘div’ does not exist on type ‘jsx.intrinsicelements'”, you can resolve it by using a React fragment or a generic JSX.IntrinsicElements type for the div element. Here’s an example of how you can do it in TypeScript:

“`tsx
import React from ‘react’;

const MyComponent: React.FC = () => {
return (
<>

This is a div element in a React fragment.


);
};

export default MyComponent;
“`

In this example, the React fragment (`<>` and ``) allows you to return multiple elements without using an additional wrapping element like a div.

If you prefer to use a div element directly and want to specify its type, you can use the JSX.IntrinsicElements type. Here’s an example:

“`tsx
import React from ‘react’;

const MyComponent: React.FC = () => {
return (

This is a div element with a className

);
};

export default MyComponent;
“`

In the above code, the `className` attribute is added as an example, but you can include any other desired attributes as well.

Remember that the TypeScript compiler might require some extra configuration to recognize JSX syntax properly. Make sure you have the necessary TypeScript and JSX configuration in your project’s tsconfig.json or via CLI arguments.

Additionally, when generating the final HTML content, React components need to be rendered into a root element, such as a div, body, or some other container. Please keep in mind that the code provided here is meant for explanation and demonstration purposes, and you need to integrate it appropriately into your application’s structure.

Similar post

Leave a comment