Wednesday, September 9, 2020

Functional Component

 Hey today we will see the functional component.

Functional Component

import React from "react";

//below we have imported a component ShowQuestion.
import ShowQuestion from "./ShowQuestion";

//This is a collection of title and content
const items = [
  {
    title: "what is react",
    content: "react is js library",
  },
  {
    title: "what is virtual dom",
    content: "it is clone of real dom",
  },
];

//this is how we make functional component using arrow function
const App = () => {
/*the app component that is a functional component returning another
component ShowQuestion*/
  return (
    <div>
       /*you can see we have passed our collection items with ShowQuestion
        component. THis is how we pass props. items is props name with
value {items}. Now this props will be used by the ShowQuestion
component.
        */
      <ShowQuestion items={items} />
    </div>
  );
};

//export your function App for accessible
export default App;

No comments:

Post a Comment