Moving function from outside to inside

I have this function working outside of the class App extends Component, but I want to move it inside since I can’t call an inner function from the outside:

    function moveToSelection(selected){
      for(let indexPath of selected){
        indexSet.add(indexPath.index);
      }
      console.log(indexSet);
    }

I am triggering it here:

    <TableView
              columns={COLUMNS}
              dataSource={ds}
              renderCell={renderCell}
              onSelectionChange={moveToSelection}
            / >

I tried just removing the “function” deceleration when moving it inside, but there seems to be more involved?

That depends on how you’re moving it and where. Then if you’re trying to access a class method inside, whether or not you’ll have context issues (value of this) which is likely that you will.

Probably the easiest way to go about it is to move it into the class as a method and then change the handler to

    onSelectionChange={event => this.moveToSelection(event)}

That should account for most problems.

1 Like

Got it, thank you!