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. Answer from WaitingForHeatDeath on reddit.com
๐ŸŒ
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> ); }
๐ŸŒ
Robin Wieruch
robinwieruch.de โ€บ react-function-component
React Function Components - Robin Wieruch
December 23, 2024 - This in-depth guide shows you everything about React Function Components, which are basically just JavaScript Functions being React Components which return JSX (Reactโ€™s Template Syntax), so that after you have read this tutorial you should be well prepared to implement modern React applications with them.
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
Creating custom function in React component
You can create functions in react components. It is actually regular ES6 class which inherits from React.Component. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Where should functions in function components go?
I'm trying to convert this cool animation I found here into a React reusable component. It looks like this component would require one parent component for the canvas, and many children components for the function Ball(). More on stackoverflow.com
๐ŸŒ stackoverflow.com
reactjs - Correct way to share functions between components in React - Stack Overflow
I'm new to React and this is another little nugget of information that's helping me along :) 2023-01-17T09:29:04.69Z+00:00 ... The constructor was the vital thing for me :) Editing to indicate that it requires super() beforehand. 2023-01-17T19:10:24.037Z+00:00 ... Here are some examples on how you can reuse a function ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_components.asp
React Components
React Compiler React Quiz React Exercises React Syllabus React Study Plan React Server React Interview Prep React Bootcamp React Certificate ... Components are like functions that return HTML elements.
๐ŸŒ
React
react.dev โ€บ reference โ€บ react โ€บ Component
Component โ€“ React
We recommend defining components as functions instead of classes. See how to migrate. Component is the base class for the React components defined as JavaScript classes.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ reactjs โ€บ reactjs-functional-components
ReactJS Functional Components - GeeksforGeeks
Functional components are the basic building blocks in React used to create and manage user interface elements.
Published ย  February 20, 2026
๐ŸŒ
React Native
reactnative.dev โ€บ docs โ€บ intro-react
React Fundamentals ยท React Native
February 20, 2026 - React and React Native use JSX, a syntax that lets you write elements inside JavaScript like so: <Text>Hello, I am your cat!</Text>. The React docs have a comprehensive guide to JSX you can refer to learn even more. Because JSX is JavaScript, you can use variables inside it. Here you are declaring a name for the cat, name, and embedding it with curly braces inside <Text>. Any JavaScript expression will work between curly braces, including function calls like {getFullName("Rum", "Tum", "Tugger")}:
๐ŸŒ
React
legacy.reactjs.org โ€บ docs โ€บ faq-functions.html
Passing Functions to Components โ€“ React
You can use an arrow function to wrap around an event handler and pass parameters: ... const A = 65 // ASCII character code class Alphabet extends React.Component { constructor(props) { super(props); this.state = { justClicked: null, letters: Array.from({length: 26}, (_, i) => String.fromCharCode(A + i)) }; } handleClick(letter) { this.setState({ justClicked: letter }); } render() { return ( <div> Just clicked: {this.state.justClicked} <ul> {this.state.letters.map(letter => <li key={letter} onClick={() => this.handleClick(letter)}> {letter} </li> )} </ul> </div> ) } }
Find elsewhere
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ function-component-vs-class-component-in-react
Function Components vs Class Components in React โ€“ With Examples
April 16, 2024 - You can think of components as custom HTML elements that encapsulate their own logic and UI structure. They can accept inputs called props (short for properties) and return React elements describing what should appear on the screen. ... Function Components: These are simple JavaScript functions that take props as input and return JSX elements.
๐ŸŒ
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 โ€บ learn โ€บ keeping-components-pure
Keeping Components Pure โ€“ React
In the above example, double is a pure function. If you pass it 3, it will return 6. Always. React is designed around this concept. React assumes that every component you write is a pure function.
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>
    )
}
๐ŸŒ
React
react.dev โ€บ reference โ€บ rules โ€บ react-calls-components-and-hooks
React calls Components and Hooks โ€“ React
React is responsible for rendering components and Hooks when necessary to optimize the user experience. It is declarative: you tell React what to render in your componentโ€™s logic, and React will figure out how best to display it to your user.
๐ŸŒ
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 - In other words, functional components accept data, or more technically, it takes props as a function argument and returns the data in valid JSX form. Below is the example for a react functional component props as an argument and returns the support in the valid JSX form.
Top answer
1 of 6
22

Are these interchangeable?

Short answer: No.


Let's take a look at the different snippets you've posted:


someFunction() vs someFunction

With the former syntax, you are actually invoking that function. The latter is just a reference to that function. So when do we use which?

  • You would use someFunction() when you want that function invoked and its result returned immediately. In React, this is typically seen when you split parts of your JSX code to a separate function; either for reasons of readability or reusability. For example:

    render() {
      myFunction() {
        return <p>Foo Bar</p>;
      }
      return (
        <div>
          {myFunction()}
        </div>
      );
    }
    

  • You would use someFunction when you want only to pass the reference to that function to something else. In React, this is usually an event handler that is passed down to another child-component via props so that that component can call the event handler when it needs to. For example:

    class myApp extends React.Component {
      doSomething() {
        console.log("button clicked!");
      }
      render() {
        return (
          <div>
            <Button someFunction={this.doSomething} />
          </div>
        );
      }
    }
    
    class Button extends React.Component {
      render() {
        return (
          <button onClick={this.props.someFunction}>Click me</button>
        );
      }
    }
    

someFunction() vs this.someFunction()

This has to do with the context of the function. Basically, "where is this function?". Is part of the current Component, then use this.someFunction(), is it part of the parent Component passed in as props, then use this.props.someFunction(). Is it a function inside the current method, then just use someFunction().

Obviously, there's a lot more to it than that, but it's the best basic summary I can give.

For a better understanding, have a read here. It is a great guide to how the this keyword works in Javascript and in React in particular.

2 of 6
4

If you want to call a function options 2 and with some assumptions 5 should work.

If you want to actually pass a function as a property to some child component so that it could call it later (say to notify your root element on some event) then option 1 (with prebind) and 3 (with defining a variable const {handleAddTodo} = this and prebind :) ) should work

// this works if handleAddTodo was prebinded or doesn't use this
handleAddTodo ={this.handleAddTodo} 

// this probably wont work unless handleAddTodo is higher order function that returns another function
handleAddTodo ={this.handleAddTodo()} 

// This wont work unless you have a var/let/const that is referencing a function
handleAddTodo ={handleAddTodo} 

// Same as 1
handleAddTodo ={this.handleAddTodo} 

// 3 and 2 combined
handleAddTodo ={handleAddTodo()} 
๐ŸŒ
W3Schools
w3schools.com โ€บ react โ€บ react_es6_arrow.asp
React ES6 Arrow Functions
React Compiler React Quiz React Exercises React Syllabus React Study Plan React Server React Interview Prep React Bootcamp React Certificate ... It gets shorter! If the function has only one statement, and the statement returns a value, you can remove the brackets and the return keyword:
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ react-components-jsx-props-for-beginners
React Functional Components, Props, and JSX โ€“ React.js Tutorial for Beginners
November 5, 2020 - After getting used to the JSX syntax, the next thing to understand is the component-based structure of React. If you revisit the example code at the top of this post, you'll see that the JSX code is being returned by a function. But the App( ) function is not an ordinary function โ€“ it is actually a component.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-to-create-a-function-in-react
How to create a function in React
Line 11: We export the HelloWorld function as the default export, allowing it to be imported into other components. Note: Each file can have only one default export, which allows a single item to be exported and imported without curly braces, while named exports enable multiple items to be exported and imported with curly braces. Understanding the distinction between default and named exports in React is essential for organizing component structure effectively.
๐ŸŒ
React TypeScript Cheatsheets
react-typescript-cheatsheet.netlify.app โ€บ function components
Function Components | React TypeScript Cheatsheets
React.FunctionComponent is explicit about the return type, while the normal function version is implicit (or else needs additional annotation).