HOME C C++ PYTHON JAVA HTML CSS JAVASCRIPT BOOTSTRAP JQUERY REACT PHP SQL AJAX JSON DATA SCIENCE AI

React Components

React Components

In React, a component is a reusable, self-contained piece of UI that can be composed together to build more complex user interfaces.

Functional Component:

Functional components are simpler and often used when the component doesn't need to manage state or lifecycle methods. They receive props as arguments and return JSX.

import React from 'react';
const FunctionalComponent = (props) => {
return (
<div>
<h1>{props.title} </h1>
<p>{props.description} </p>
</div>
);
};
export default FunctionalComponent;

In this example:

  • The 'FunctionalComponent' is a function that takes 'props' as an argument.
  • It returns JSX that defines the structure of the component.
  • The component can be used in other parts of your application by importing and rendering it.

  • import React from 'react';
    import FunctionalComponent from './FunctionalComponent';
    const App = () => {
    return (
    <div>
    <FunctionalComponent title="Functional Component" description="This is a functional component." />
    </div>
    );
    };
    export default App;