React.js function in functional component

In a functional React component, you can define a function within the component's body and call it as needed. Here is an example of a simple functional component that has a function called handleClick:
import React from 'react'; const MyComponent = () => { const handleClick = () => { console.log('Button was clicked!'); } return ( <button onClick={handleClick}>Click me</button> ); } export default MyComponent;

In this example, the handleClick function is defined inside the component and is passed as the onClick event handler for a button element. When the button is clicked, the handleClick function will be called and the message "Button was clicked!" will be logged to the console.

It's also possible to define function outside of the functional component and then pass it in as a props.

import React from 'react'; const handleClick = () => { console.log('Button was clicked!'); } const MyComponent = (props) => { return ( <button onClick={props.handleClick}>Click me</button> ); } export default MyComponent;

Here the function handleClick is defined outside of the component and passed as a props to the component.