How to avoid bind or inline arrow functions inside render method

We should avoid method binding inside render because during re-rendering it will create the new methods instead of using the old one, that will affect the performance.

So for the scenarios like this:

<input onChange = { this._handleChange.bind(this) } ...../>

We can bind _handleChange method either in constructor:

this._handleChange = this._handleChange.bind(this);

Or we can use property initializer syntax:

_handleChange = () => {....}

Now lets consider the case where we want to pass some extra parameter, lets say in a simple todo app, onclick of item i need to delete the item from array, for that i need to pass either the item index or the todo name in each onClick method: => <div key={el} onClick={this._deleteTodo.bind(this, el)}> {el} </div>)

For now just assume that todo names are unique.

As per DOC:

The problem with this syntax is that a different callback is created each time the component renders.


How to avoid this way of binding inside render method or what are the alternatives of this?

Kindly provide any reference or example, thanks.

First: A simple solution will be to create a component for the content inside a map function and pass the values as props and when you call the function from the child component you can pass the value to the function passed down as props.


deleteTodo = (val) => {
} => 
    <MyComponent val={el} onClick={this.deleteTodo}/> 



class MyComponent extends React.Component {
    deleteTodo = () => {
    render() {
       return <div  onClick={this.deleteTodo}> {this.props.val} </div>

Sample snippet

class Parent extends React.Component {
     _deleteTodo = (val) => {
    render() {
        var todos = ['a', 'b', 'c'];
        return (
           <div>{ => 
             <MyComponent key={el} val={el} onClick={this._deleteTodo}/> 

class MyComponent extends React.Component {
        _deleteTodo = () => {
                     console.log('here');   this.props.onClick(this.props.val);
        render() {
           return <div onClick={this._deleteTodo}> {this.props.val} </div>
ReactDOM.render(<Parent/>, document.getElementById('app'));
<script src=""></script>
<script src=""></script>
<div id="app"></div>


Second: The other approach to it would be to use memoize and return a function

constructor() {
    this._deleteTodoListener = _.memoize(
                   this._deleteTodo, (element) => {
                        return element.hashCode();

_deleteTodo = (element) => {
   //delete handling here

and using it like => <div key={el} onClick={this._deleteTodoListener(el)}> {el} </div>)

P.S. However this is not a best solution and will still result in multiple functions being created but is still an improvement over the initial case.

Third: However a more appropriate solution to this will be to add an attribute to the topmost div and get the value from event like

_deleteTodo = (e) => {

 } => <div key={el} data-value={el} onClick={this._deleteTodo}> {el} </div>)

However, in this case the attributes are converted to string using toString method and hence and object will be converted to [Object Object] and and array like ["1" , "2", "3"] as "1, 2, 3"

This answer is definitely exhaustive, but I'd say it's better to solve this problem by implementing a proper shouldComponentUpdate in the child component.

Even if the props are exactly the same, the following code will still re-render children unless they prevent it in their own shouldComponentUpdate (they might inherit it from PureComponent):

handleChildClick = itemId => {}

render() {
    return => <Child onClick={this.handleChildClick} data={itemData})


So, in order to avoid re-renders, the child component has to implement shouldComponentUpdate anyway. Now, the only reasonable implementation is completely ignoring onClick regardless of whether it has changed:

shouldComponentUpdate(nextProps) {
    return this.props.array !== nextProps.array;

How to avoid this way of binding inside render method or what are the alternatives of this?

If you care about re-rendering then shouldComponentUpdate and PureComponent are your friends and they will help you optimize rendering.

You have to extract "Child" component from the "Parent" and pass always the same props and implement shouldComponentUpdate or use PureComponent. What we want is a case when we remove a child, other children shouldn't be re-rendered.


import React, { Component, PureComponent } from 'react';
import { render } from 'react-dom';

class Product extends PureComponent {
  render() {
    const { id, name, onDelete } = this.props;

    console.log(`<Product id=${id} /> render()`);
    return (
        {id} - {name}
        <button onClick={() => onDelete(id)}>Delete</button>

class App extends Component {
  constructor(props) {

    this.state = {
      products: [
        { id: 1, name: 'Foo' },
        { id: 2, name: 'Bar' },

    this.handleDelete = this.handleDelete.bind(this);

  handleDelete(productId) {
    this.setState(prevState => ({
      products: prevState.products.filter(product => !== productId),

  render() {
    console.log(`<App /> render()`);
    return (
   => (

render(<App />, document.getElementById('root'));


Expected behaviour

  • <App /> render()
  • <Product id=1... render()
  • <Product id=2... render()

When we remove <Product id=2 ... only <App /> is re-rendered.

  • render()

To see those messages in demo, open the dev tools console.

The same technique is used and described in article: React is Slow, React is Fast: Optimizing React Apps in Practice by François Zaninotto.

Documentation encourages to use data-attributes and access them from within

_deleteTodo = (evt) => {
  const elementToDelete =;
  this.setState(prevState => ({
    todos: prevState.todos.filter(el => el !== elementToDelete)

// and from render:
  el => <div key={el} data-el={el} onClick={this._deleteTodo}> {el} </div>

Also note that this makes sense only when you have performance issues:

Is it OK to use arrow functions in render methods?

Generally speaking, yes, it is OK, and it is often the easiest way to pass parameters to callback functions.

If you do have performance issues, by all means, optimize!