DEV Community

Discussion on: How to Bind 'this' in React Without a Constructor

joelnet profile image
JavaScript Joel

In your "messy" example, I believe the code should be even messier. The bind won't mutate the original function, but will return a new and bound function. So you must also set this to overwrite the original function.

class SomeCompenent extends React.Component {
   constructor() {
    // this does not modify the original function

    // this binds the original function
    this.renderSomeInput = this.renderSomeInput.bind(this);