A functional component in React is a JavaScript function that returns a React component. They are often used for simple components that only need to render some UI based on their props and state.
Here's an example of a simple functional component in React:
import React from 'react';
const FunctionName= (props) => {
return (
<div>
<h1>Hello, {props.name}!</h1>
</div>
);
};
export default FunctionName;
import React from 'react';
const Hello= (props) => {
return (
<div>
<h1>Hello, {props.name}!</h1>
</div>
);
};
export default Hello;
In this example, the Hello component is defined as a function that takes in props as its argument. The component returns a div element that displays a greeting with the name passed in through its props. The component is then exported as the default export so it can be imported and used in another file.
Post a Comment