DEV Community

Ramya Yegu
Ramya Yegu

Posted on

Is it possible to create custom tag like <If> with condition using jsx ?

Top comments (1)

Collapse
 
bhavyashah profile image
Bhavyashah • Edited

Yes in react you can make your own elements like if you want to make elements.
Like an example given below:

1) Make a file of index.js in that you have to write code like given in image:

import React from 'react';
import ReactDOM from 'react-dom';
import If from './If';

ReactDOM.render(
  <>
    <If />
  </>
  , document.getElementById("root")
);
Enter fullscreen mode Exit fullscreen mode

2) Now Make a File with If.jsx and this code

import React from 'react';

const If = () =>{
return ( <>
<h1> Hello World </h1>
</>
);
}
export default If;
Enter fullscreen mode Exit fullscreen mode

3) Now save it and run this code and you will see the output like this:

Hello World