The first thing to note is that stateless functional components cannot have methods: You shouldn't count on calling update or draw on a rendered Ball if it is a stateless functional component.

In most cases you should declare the functions outside the component function so you declare them only once and always reuse the same reference. When you declare the function inside, every time the component is rendered the function will be defined again.

There are cases in which you will need to define a function inside the component to, for example, assign it as an event handler that behaves differently based on the properties of the component. But still you could define the function outside Ball and bind it with the properties, making the code much cleaner and making the update or draw functions reusable:

// you can use update somewhere else
const update = (propX, a, b) => { ... };
    
const Ball = props => (
  <Something onClick={update.bind(null, props.x)} />
);

If you're using hooks, you can use useCallback to ensure the function is only redefined when any of its dependencies change (props.x in this case):

const Ball = props => {
  const onClick = useCallback((a, b) => {
    // do something with a, b and props.x
  }, [props.x]);

  return (
    <Something onClick={onClick} />
  );
}

This is the wrong way:

const Ball = props => {
  function update(a, b) {
    // props.x is visible here
  }
    
  return (
    <Something onClick={update} />
  );
}

When using useCallback, defining the update function in the useCallback hook itself or outside the component becomes a design decision more than anything: You should take into account if you're going to reuse update and/or if you need to access the scope of the component's closure to, for example, read/write to the state. Personally I choose to define it inside the component by default and make it reusable only if the need arises, to prevent over-engineering from the start. On top of that, reusing application logic is better done with more specific hooks, leaving components for presentational purposes. Defining the function outside the component while using hooks really depends on the grade of decoupling from React you want for your application logic.

Another common discussion about useCallback is whether to always use it for every function or not. That is, treat is as opt-in or always recommendable. I would argue to always use useCallback: I've seen many bugs caused by not wrapping a function in useCallback and not a single scenario where doing so affects the performance or logic in any way. In most cases, you want to keep a reference while the dependencies don't change, so you can use the function itself as a dependency for other effects, memos or callback. In many cases the callback will be passed as a prop to other elements, and if you memoized it with useCallback you won't change the props (thus re-render) other components independently of how cheap or costly that would be. I've seen many thousands of functions declared in components and not a single case in which using useCallback would have any down side. On the other hand most functions not memoized with useCallback would eventually be changed to do so, causing serious bugs or performance issues if the developer doesn't recognize the implications of not doing so. Technically there is a performance hit by using useCallback, as you would be creating and additional function but it is negligible compared to the re-declaration of the function that always has to happen either you use useCallback or not and the overall footprint of React and JavaScript. So, if you are really concerned about the performance impact of useCallback versus not using it, you should be questioning yourself if React is the right tool for the job.

Answer from Marco Scabbiolo on Stack Overflow
Top answer
1 of 5
231

The first thing to note is that stateless functional components cannot have methods: You shouldn't count on calling update or draw on a rendered Ball if it is a stateless functional component.

In most cases you should declare the functions outside the component function so you declare them only once and always reuse the same reference. When you declare the function inside, every time the component is rendered the function will be defined again.

There are cases in which you will need to define a function inside the component to, for example, assign it as an event handler that behaves differently based on the properties of the component. But still you could define the function outside Ball and bind it with the properties, making the code much cleaner and making the update or draw functions reusable:

// you can use update somewhere else
const update = (propX, a, b) => { ... };
    
const Ball = props => (
  <Something onClick={update.bind(null, props.x)} />
);

If you're using hooks, you can use useCallback to ensure the function is only redefined when any of its dependencies change (props.x in this case):

const Ball = props => {
  const onClick = useCallback((a, b) => {
    // do something with a, b and props.x
  }, [props.x]);

  return (
    <Something onClick={onClick} />
  );
}

This is the wrong way:

const Ball = props => {
  function update(a, b) {
    // props.x is visible here
  }
    
  return (
    <Something onClick={update} />
  );
}

When using useCallback, defining the update function in the useCallback hook itself or outside the component becomes a design decision more than anything: You should take into account if you're going to reuse update and/or if you need to access the scope of the component's closure to, for example, read/write to the state. Personally I choose to define it inside the component by default and make it reusable only if the need arises, to prevent over-engineering from the start. On top of that, reusing application logic is better done with more specific hooks, leaving components for presentational purposes. Defining the function outside the component while using hooks really depends on the grade of decoupling from React you want for your application logic.

Another common discussion about useCallback is whether to always use it for every function or not. That is, treat is as opt-in or always recommendable. I would argue to always use useCallback: I've seen many bugs caused by not wrapping a function in useCallback and not a single scenario where doing so affects the performance or logic in any way. In most cases, you want to keep a reference while the dependencies don't change, so you can use the function itself as a dependency for other effects, memos or callback. In many cases the callback will be passed as a prop to other elements, and if you memoized it with useCallback you won't change the props (thus re-render) other components independently of how cheap or costly that would be. I've seen many thousands of functions declared in components and not a single case in which using useCallback would have any down side. On the other hand most functions not memoized with useCallback would eventually be changed to do so, causing serious bugs or performance issues if the developer doesn't recognize the implications of not doing so. Technically there is a performance hit by using useCallback, as you would be creating and additional function but it is negligible compared to the re-declaration of the function that always has to happen either you use useCallback or not and the overall footprint of React and JavaScript. So, if you are really concerned about the performance impact of useCallback versus not using it, you should be questioning yourself if React is the right tool for the job.

2 of 5
20

You can place functions inside stateless functional components:

function Action() {
    function handlePick(){
        alert("test");
    }

    return (
        <div>
            <input type="button" onClick={handlePick} value="What you want to do ?" />
        </div>
    )
}

But it's not a good practice as the function handlePick() will be defined every time the component is rendered.

It would be better to define the function outside the component:

function handlePick(){
    alert("test");
}

function Action() {
    return (
        <div>
            <input type="button" onClick={handlePick} value="What you want to do ?" />
        </div>
    )
}
🌐
Robin Wieruch
robinwieruch.de › react-function-component
React Function Components - Robin Wieruch
December 23, 2024 - Then in the Function Component the props object is available as argument in the function signature. Since props are always coming as object, and most often you need to extract the information from the props anyway, JavaScript object destructuring comes in handy. You can directly use it in the function signature for the props object: ... import React from 'react'; function App() { const greeting = 'Hello Function Component!'; return <Headline value={greeting} />; } function Headline({ value }) { return <h1>{value}</h1>; } export default App;
Discussions

Am I supposed to never create functions inside React functional components?
It is fine to put functions inside your react components. If you are concerned about recreating them on each render, check out the useCallback hook. But generally you don't need to pre-optimize. More on reddit.com
🌐 r/react
20
13
December 7, 2022
reactjs - Difference between Regular JavaScript functions and React Functional Component - Stack Overflow
Explore Stack Internal ... From this post it seems like there is no difference and it is just different way of writing. Please provide an example to make the difference more clear. ... A function component is a function that returns react elements (or null), and which you intend to use via ... More on stackoverflow.com
🌐 stackoverflow.com
Class vs functional components
"Would anyone here architect a new app today primarily with class components?" No More on reddit.com
🌐 r/reactjs
191
203
June 10, 2023
Are functional components pure components ?
I assume that by “functional component” you mean components defined as functions (as opposed to class components). In that case no, function components are definitely not “pure” by nature. They can be, but it’s not implicit in their definition. A pure function is a function that always returns the same output given the same input, making it independent of other external sources which could alter its output. A function component can easily depend on contexts, stores, external APIs, etc… making it not necessarily pure. A pure function component can exist though. It’s the case of UI presentation components which just takes some inputs and render something solely based on that. More on reddit.com
🌐 r/reactjs
26
21
October 11, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs-functional-components
ReactJS Functional Components | GeeksforGeeks
Return JSX: Functional components return JSX (a syntax extension that allows HTML-like code inside JavaScript). No, this keyword: Unlike class components, functional components do not have a this context. Hooks: With hooks, functional components can manage state and side effects, making them just as powerful as class components. ... import React from 'react'; const MyComp = (props) => { return <div>Hello, {props.name}!</div>; }; export default MyComp;
Published   February 17, 2025
🌐
React
legacy.reactjs.org › docs › components-and-props.html
Components and Props – React
However, if you integrate React into an existing app, you might start bottom-up with a small component like Button and gradually work your way to the top of the view hierarchy. Don’t be afraid to split components into smaller components. ... function Comment(props) { return ( <div className="Comment"> <div className="UserInfo"> <img className="Avatar" src={props.author.avatarUrl} alt={props.author.name} /> <div className="UserInfo-name"> {props.author.name} </div> </div> <div className="Comment-text"> {props.text} </div> <div className="Comment-date"> {formatDate(props.date)} </div> </div> ); }
🌐
DEV Community
dev.to › igor_bykov › react-calling-functional-components-as-functions-1d3l
React: Calling functional components as functions - DEV Community
August 27, 2020 - In fact, the author of the post shares a link to a Babel plug-in that (instead of creating React elements) helps in calling your components directly. I haven't found a single mention about calling functional components directly in React docs, however, there is one technique where such a possibility is demonstrated - render props.
🌐
Reddit
reddit.com › r/react › am i supposed to never create functions inside react functional components?
r/react on Reddit: Am I supposed to never create functions inside React functional components?
December 7, 2022 -

https://beta.reactjs.org/learn/adding-interactivity#state-a-components-memory

export default function Gallery() {
  const [index, setIndex] = useState(0);
  const [showMore, setShowMore] = useState(false);

  function handleNextClick() {
    setIndex(index + 1);
  }

  function handleMoreClick() {
    setShowMore(!showMore);
  }
....

So on every render we are creating new functions handleNextClick, handleMoreClick

Should we pull these out of Gallery and pass the "set" state functions as parameters?

I only ask this because I read somewhere best practice is to NOT have functions inside your React functional components <-- trying to confirm if this is true? Small functions allowed? Doesn't matter?

🌐
React
react.dev › reference › react › Component
Component – React
To avoid recalculating the initial state, pass a function to useState. If you define componentDidCatch, React will call it when some child component (including distant children) throws an error during rendering.
Find elsewhere
🌐
W3Schools
w3schools.com › react › react_components.asp
React Components
It is now suggested to use Function components along with Hooks, instead of Class components. Class components are still supported, check the Class components section for more information. When creating a React component, the component's name MUST start with an upper case letter.
🌐
freeCodeCamp
freecodecamp.org › news › a-few-questions-on-functional-components
How to Use Functional Components in React
May 3, 2020 - Passing an update function allows you to access the current state value inside the updater. OK so increment() gets called with the current n state and it is used to compute the new state value. Let’s summarize what we found out. In React we can simply define a component using a function that ...
🌐
InfoWorld
infoworld.com › home › software development › programming languages › javascript
How to use React functional components | InfoWorld
January 14, 2021 - A function provides the simplest way to interact with the component rendering engine. The functional version, instead of calling ReactDOM.render(), simply returns a value, which is also JSX.
🌐
Upgrad
upgrad.com › home › blog › software development › react functional components with examples [in-depth guide]
React Functional Components: In-Depth and Detailed Guide | upGrad blog
April 15, 2025 - React functional components are just normal JavaScript functions; we can create them using specific function keywords. Most developers create functional components using the Arrow function.
🌐
ScholarHat
scholarhat.com › home
React Functional Components: Complete Guide with Example
A React functional component is a JavaScript function that accepts props as an argument and returns a React element (usually written in JSX) to render a portion of the user interface.
Published   September 11, 2025
🌐
Groove Technology
groovetechnology.com › home › blog › technologies › reactjs functional components: everything you need to know
ReactJS Functional Components: A Complete Overview
September 26, 2024 - ReactJS functional components are JavaScript functions that return a JSX element, which is a template that describes the structure of the component. The JSX element resembles HTML, but it has some unique syntax that allows it to be transformed ...
🌐
LogRocket
blog.logrocket.com › home › pure components in react: using purecomponent and react.memo
Pure components in React: Using PureComponent and React.memo - LogRocket Blog
March 4, 2025 - A functional component is a plain JavaScript function that returns JSX. A class component is a JavaScript class that extends React.Component and returns JSX inside a render method.
Top answer
1 of 2
2

All React Function Components are regular Javascript functions.

Not all regular Javascript functions are React Function Components.

Function components are just a signature for a specific function.

You can look at the Typescript definition to see exactly what that signature is:

    interface FunctionComponent<P = {}> {
        (props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
        propTypes?: WeakValidationMap<P> | undefined;
        contextTypes?: ValidationMap<any> | undefined;
        defaultProps?: Partial<P> | undefined;
        displayName?: string | undefined;
    }

Reference: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/v17/index.d.ts#L542

And PropsWithChildren is defined as:

type PropsWithChildren<P> = P & { children?: ReactNode | undefined };

Reference: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/v17/index.d.ts#L822

The JSX parser will translate JSX and pass certain parameters to these functions.

JSX:

<CompOne someProperty="someValue"><CompTwo/></CompOne>

Equivalent to:

CompOne({someProperty: "someValue", children: CompTwo({})})

The signature is just letting you know how the JSX will be parsed, so you know how to access those parameters within your function.

The signature includes some additional info as well: the function should return a ReactElement or null, and it can have those four properties.


For example, I'm trying to log the someProperty value from CompOne:

<CompOne someProperty="someValue" someOtherProp="someOtherValue" />
CompOne(someProperty) {
  console.log(someProperty); // logs {someProperty: "someValue", someOtherProp: "someOtherValue"}
  return null;
}

This is incorrect, because I was not using the function as the Function Component signature describes. The JSX parser reads the properties into an object, and passes it as the first parameter to the function. Although the code will still execute, it is not what I intended to happen.

CompOne(props) {
  console.log(props.someProperty); // logs "someValue"
  return null;
}

This works as intended because I know the structure of a Function Component.

2 of 2
-1

I have tried my best to keep it as simple as I can for your understanding:-

Javascript functions:-

function add(a, b) {
  return a + b;
}

React functional component:-

import React from 'react';

const DisplayMessage = (props) => {
  return <h1>{props.message}</h1>;
};

export default DisplayMessage;

  1. USE:- JS functions are particular to do a thing. as you see in the example it will do the addition of two numbers only.while React functional components are used to define components in React that can be rendered to the UI. The display component will render the functional component.

  2. DEFINITION:- JS functions are defined using the function keyword, while React functional components are defined using the const keyword and an arrow function.

  3. PROPS:- We can pass and receive props to react functional components but not too regular JS functions.

  4. STATE:- JS function doesn't have any state while React functional component when declared in classes will have the state.

  5. RENDERING:- JS function doesn't render any change in the value.while React functional component re-render on every state or props change.

🌐
W3Schools
w3schools.io › learn › react-typescript-functional-components
The Ultimate Guide to Building Functional Components in React Typescript - w3schools
Normal Function with ES6 props destructuring assignment props object is declared with destructuring assignment syntax. You have full control over optional parameters. In the below, Component, MessageProps contains a message and an optional user. with destructuring syntax, you can pass the property names with optional parameters as seen below · import React, { FC } from 'react'; interface MessageProps { message: string; user?: string } function FunctionalComponent({message,user="loggeduser"}:MessageProps){ return ( <> <h1>Welcome {message} - {user}</h1> </> ); }; export default FunctionalComponent;
🌐
React
react.dev › learn › keeping-components-pure
Keeping Components Pure – React
You could think of your components as recipes: if you follow them and don’t introduce new ingredients during the cooking process, you will get the same dish every time. That “dish” is the JSX that the component serves to React to render. ... React’s rendering process must always be pure. Components should only return their JSX, and not change any objects or variables that existed before rendering—that would make them impure! ... let guest = 0; function Cup() { // Bad: changing a preexisting variable!
🌐
LogRocket
blog.logrocket.com › home › fundamentals of functional programming with react
Fundamentals of functional programming with React - LogRocket Blog
June 4, 2024 - This is similar to a pure function in JavaScript where a function receives an argument (in this case, a count prop) and uses the prop to render an output. React, however, has unidirectional data flow from the parent to child component.