# Functional Components

## A Simple Functional Component

Use **regular function** to write a functional component.

{% tabs %}
{% tab title="index.js" %}

```jsx
import React from "react"
import ReactDOM from "react-dom"

// Functional Component
function MyInfo(){
  return(
    <div>
      <h1>Mahmud Sajib</h1>
      <p>Hi, I love to write code & drink coffee!</p>
      <ul>
        <li>India</li>
        <li>Nepal</li>
        <li>Srilanka</li>
      </ul>
    </div>
  )
}

// Render JSX Element
ReactDOM.render(
  <MyInfo />,
  document.getElementById("root")
)
```

{% endtab %}

{% tab title="index.html" %}

```markup
<html>
    <head>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div id="root"></div>
        <script src="index.pack.js"></script>
    </body>
</html>
```

{% endtab %}
{% endtabs %}

## Move Components into Separate Files

To keep code clean, it's a good practice to move components into their own separate file.&#x20;

{% tabs %}
{% tab title="MyInfo.js" %}

```jsx
import React from "react"

// Functional Component
function MyInfo(){
  return(
    <div>
      <h1>Mahmud Sajib</h1>
      <p>Hi, I love to write code & drink coffee!</p>
      <ul>
        <li>India</li>
        <li>Nepal</li>
        <li>Srilanka</li>
      </ul>
    </div>
  )
}

// Exporting Our Component
export default MyInfo

```

{% endtab %}

{% tab title="index.js" %}

```jsx
import React from "react"
import ReactDOM from "react-dom"

// Importing Our Component
import MyInfo from "./MyInfo"

// Render JSX Element
ReactDOM.render(
  <MyInfo />,
  document.getElementById("root")
)
```

{% endtab %}

{% tab title="index.html" %}

```markup
<html>
    <head>
        <link rel="stylesheet" href="style.css">
    </head>
    <body>
        <div id="root"></div>
        <script src="index.pack.js"></script>
    </body>
</html>
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Always name the `.js` folder name  after the **functional component's** name.&#x20;
{% endhint %}

##
