0

Actions allows me to load a page from a button. So I would have e.g. 'page1' as a key (which is a function), that i could apply to Actions.page1 and it would navigate to that page. However, here I am only getting the string of this.props.lec, that holds the same characters as the key/funcion that I want. Thus when building get the error message of: 'category is not a function (evaluating '_reactNativeFlux.Actions.a({id: this.props.id, title: this.props.title})'. So I believe it will not work because its a string and not a function. So how would i make it as a function?

  var a = this.props.lec;
  _onPress() {
    Actions.a({id: this.props.id, title: this.props.title});
  }
Chris Henry
  • 199
  • 1
  • 1
  • 13
  • Possible duplicate of [Javascript: variable as array key](https://stackoverflow.com/questions/12244483/javascript-variable-as-array-key) – Brahma Dev Mar 25 '18 at 13:20

2 Answers2

1

Use square brackets, like you would with an array.

var obj = {
    something: 'ok'
}
var key = 'something';
console.log( obj[ key ] ) ==> 'ok'
Ben West
  • 4,398
  • 1
  • 16
  • 16
1

Like Ben said, you will need to use square brackets. However you need to pass arguments as well.

The correct way to go is:

const { id, lec, title } = this.props; /* added for simplicity */
Actions[lec].call(undefined, { id, title });
Daniel Stoyanoff
  • 1,443
  • 1
  • 9
  • 25