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
🌐
Robin Wieruch
robinwieruch.de › react-function-component
React Function Components - Robin Wieruch
December 23, 2024 - The function executes delayed without any further instructions from your side within the component. The component will also rerender asynchronously in case props or state have changed. Take the following code as example to see how we set state with a artificial delay by using setTimeout: ... import React, { useState } from 'react'; const App = () => { const [count, setCount] = useState(0); const handleIncrement = () => setTimeout( () => setCount(currentCount => currentCount + 1), 1000 ); const handleDecrement = () => setTimeout( () => setCount(currentCount => currentCount - 1), 1000 ); return ( <div> <h1>{count}</h1> <Button handleClick={handleIncrement}>Increment</Button> <Button handleClick={handleDecrement}>Decrement</Button> </div> ); }; const Button = ({ handleClick, children }) => ( <button type="button" onClick={handleClick}> {children} </button> ); export default App;
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › reactjs-functional-components
ReactJS Functional Components - GeeksforGeeks
Props: Functional components receive input data through props, which are objects containing key-value pairs. Processing Props: After receiving props, the component processes them and returns a JSX element that defines the component's structure ...
Published   February 20, 2026
Discussions

Where should functions in function components go?
When using useCallback, defining ... 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 ... More on stackoverflow.com
🌐 stackoverflow.com
How to declare Functional Components - Declarations vs Expressions?
3. I don’t understand the trend of using arrow functions where a function declaration will suffice, it does the const assignment for you. Also, I use ‘type’ instead of interface. My source code is 0.05% smaller than everyone else’s, that’s at least an extra sip or two of coffee per day More on reddit.com
🌐 r/reactjs
25
7
December 7, 2023
Functional vs Class Components
I’ve never seen a framework addition so quickly embraced as functional components were. I could give you technical arguments, but they wouldn’t really click until you build something big enough to matter. Know that the React dev community made the decision years ago. Use functional components. More on reddit.com
🌐 r/reactjs
95
136
December 20, 2022
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
People also ask

What is a functional component in React
divFunctional Components in React are some of those JavaScript functions which gives the return value as React elementsJSX These are typically used to define certain components in a React Application in a more simple and concise waydiv
🌐
scholarhat.com
scholarhat.com › home
React Functional Components: Complete Guide with Example
Why use functional components React
divFunctional Components are used to create a simple more concise and readable code in React Especially with the introduction of Hooks it has become easier to manage state and reuse code which is not the case with Class Componentsdiv
🌐
scholarhat.com
scholarhat.com › home
React Functional Components: Complete Guide with Example
What is the difference between props and state
divProps are basically used to pass data into a component from its parent component and they can not be changed within the component While State represents the internal data of the component and can be modifieddiv
🌐
scholarhat.com
scholarhat.com › home
React Functional Components: Complete Guide with Example
🌐
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 - ... import React from 'react'; const Dashboard = () => { return <h1>This is dashboard component</h1>; }; export default Dashboard; Below is the example for importing the component using the import keyword -
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>
    )
}
🌐
ScholarHat
scholarhat.com › home
React Functional Components: Complete Guide with Example
With the Pure React Function Component, whenever you type anything in the input field, the App component would update its state, rerenders, and also re-renders the Count component. When you are searching for a type system for your React application, you can try out TypeScript for React Components. TypeScript offers plenty of benefits to a developer. For example, it provides IDE support and can make the code base robust.
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 - Props are the primary way of passing data between components in ReactJS. To pass props to a functional component, you can simply define them as parameters in the function definition. Here’s an example:
Find elsewhere
🌐
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 ...
🌐
React
react.dev › reference › react › Component
Component – React
Reading an external data source and forcing class components to re-render in response to its changes with forceUpdate has been superseded by useSyncExternalStore in function components. If you implement getSnapshotBeforeUpdate, React will call it immediately before React updates the DOM. It enables your component to capture some information from the DOM (e.g. scroll position) before it is potentially changed. Any value returned by this lifecycle method will be passed as a parameter to componentDidUpdate. For example, you can use it in a UI like a chat thread that needs to preserve its scroll position during updates:
🌐
Medium
medium.com › @bhanu.mt.1501 › react-functional-component-6d21650c193b
React Functional Component. Functional Components | by Bhanu Maniktahla | Medium
August 27, 2023 - Creating components using the arrow function is more accessible, and the code looks clean; anyone can easily understand the code. It also has one more advantage; Arrow functions handle this context in a lexical way, whereas normal functions do it dynamically. import React from "react"; const Video = (props) => { return <h1> Video Component - {props.name}</h1> } export default Video; --------------------------------- import React from 'react'; import Video from "./components/Video"; import './App.css'; function App() { return ( <div className="App"> <Video /> </div> ); }
🌐
InfoWorld
infoworld.com › home › software development › programming languages › javascript
How to use React functional components | InfoWorld
January 14, 2021 - The variable name, in this case votes, exposes a variable that can be referenced by the template and code as seen here in {votes}. To update the variable, the variable modifier function is used, in this case setVotes. To interact with this state modifier, a button with a standard React event handler has been added. As always with React, state is only modified via the setter, never accessed directly (that is, you don’t write votes++). The fundamental purpose of useEffect is to allow React’s render engine to reach inside component functions and initiate some action, to cause some effect.
🌐
Medium
medium.com › @zachlandis91 › react-hooks-and-functional-components-25a0bc00e023
React Hooks and Functional Components | by Zach Landis | Medium
February 9, 2024 - With the help of React Hooks, ... **React Hooks functional components**. For instance, the `useState` and `useEffect` Hooks bring the capability to handle both local state and side effects, such as data fetching, to functional components, which ...
🌐
Codersera
codersera.com › blog › react-functional-components
Complete Overview of React Functional Components
March 31, 2023 - We can access the target input’s value inside of the onChangeHandler by accessing the e.target.value. Hence, to log the name of the input field, we can log e.target.name · React hook for the state: state (explain with example) React Hooks are functions that enable us to access React’s state and lifecycle properties from function components.
🌐
YouTube
youtube.com › dave gray
React JS Functional Components | Learn ReactJS - YouTube
Web Dev Roadmap for Beginners (Free!): https://bit.ly/DaveGrayWebDevRoadmapIn this tutorial you will learn how to create React JS Functional Components. This...
Published   June 21, 2021
Views   40K
🌐
Swiftorial
swiftorial.com › tutorials › react › components › functional components
Functional Components | Components | React Tutorial
August 22, 2025 - // Using props in a functional component import React from 'react'; function Welcome(props) { return <h1>Hello, {props.name}!</h1>; } export default Welcome; // Using the Welcome component import React from 'react'; import ReactDOM from 'react-dom'; import Welcome from './Welcome'; ...
🌐
DEV Community
dev.to › igor_bykov › react-calling-functional-components-as-functions-1d3l
React: Calling functional components as functions - DEV Community
August 27, 2020 - It's just not obvious because React re-mounts the component so fast, that we can't notice and since this component has no inner state, it's not getting lost as in case of CounterWithWeekday. But why directly calling CounterWithWeekday resolves the bug as well? Is it documented somewhere that you can just call a functional ...
🌐
PureCode AI
blogs.purecode.ai › home › react functional components: how to effectively utilize them
React Functional Components: How to Effectively Utilize Them - Blogs
September 30, 2025 - Moreover, Hooks enable function components to handle state and side effects, resulting in function components with state. A later section will discuss the React Hooks available to functional components. The code example below shows how to create a stateful function component:
🌐
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 - In essence, stateless function components are JavaScript functions that return React items after receiving props as input. Stateless functional components are used when a component doesn’t need to maintain its own state or lifecycle methods. Typically, these components have consistent output based on their inputs because they have no state or side effects. ... If you give a stateless function component a set of props, it will always render the same JSX. A simple example is: