Search code examples
reactjsreact-nativereact-props

React native - Returning a string after this.props


I'm a complete begginer in React native and javascript in general. I need to return a combination of two props inside a component. I have a data prop in a JSON format and a string prop that represent what im supposed to return from the data.

_displayText = (id) => {
   var text = this.props.selectedRows[id].label
   const {data} = this.props
   return(......)
}

So here the text variable contains something like "pv_id_workstream.label". Is it possible to return something like data.(the result of text) ?


Solution

  • return data[text] is probably what you are looking for.