gatwirival
gatwirival

Reputation: 313

JSX has no corresponding closing tag. ts(17014)

I am quite a newbie in react .getting this error Jsx fragment has no corresponding closing tag here is my code

cart.js

import React from "react";

  export default function Cart(){

    return < > Cart < />
}

add product.js

import react from "react";

    export default function addproduct() {

      return < > addproduct < />

}

Upvotes: 0

Views: 3371

Answers (3)

gatwirival
gatwirival

Reputation: 313

got a solution from prettier messes up jsx fragments seems when i saved my work it got messy because i had not installed Prettier plugin .Did so and the problem was solved.

If that does not work for you Save without formatting to do that use

command+shift+p

to open the command palette and type "save without" until you see "file:"save without formatting"click it to save without formatting if installing prettier does not work

Upvotes: 0

coderboy
coderboy

Reputation: 769

For your editor to make automatic changes in your code, i think you need to check the .editorconfig file and disable any automatic format of the codes.

You could as well install the cool code formatter Prettier, it formats your code very nicely ans could solve your problem.

Upvotes: 1

Shmili Breuer
Shmili Breuer

Reputation: 4147

The spaces are likely added due to your VS code configuration, as a workaround you can use React.Fragment instead of the empty tags like this

 <React.Fragment>addproduct</React.Fragment>

Upvotes: 0

Related Questions