0

I'm making something in React Native and there's a module where I have a variable called jorge

const jorge = "This is some output"; 
console.log(jorge);            //output: 'This is some output'

I've passed props item to this module (I'm using the react-native-router-flux module, which also has a value of jorge:

<Scene
    key="sceneTwo"
    component={componentItem}
    title={content.title}
    item="jorge"
 />

I'd like to be able to do this:

console.log(this.props.item);  //output: 'This is some output'

Whereas in reality, I get this:

console.log(this.props.item);  //output: 'jorge'

I'm not sure what this technique is called hence the extremely vague title, but if anyone can suggest how I'd tackle this I'd be very grateful!

7
  • are you passing 'jorge' or jorge as the prop? Commented Mar 29, 2017 at 22:21
  • How did you pass it? Commented Mar 29, 2017 at 22:21
  • You can't really get a variable that way. Is jorge the property of an object (i.e., you can access it using obj.jorge)? Perhaps window.jorge? Then you can access it via "bracket syntax" like org[this.props.item]. Commented Mar 29, 2017 at 22:24
  • 2
    This is one of those things like when you get to the point where you want your car to be able to pump water out of itself so you can get to the other side of the river. The real problem is that a design mistake was made a few steps back. Commented Mar 29, 2017 at 22:26
  • 1
    <Scene key="sceneTwo" component={componentItem} title={content.title} item={jorge} /> Look at curly braces around jorge. I assume that jorge is in the scope. Commented Mar 29, 2017 at 22:27

2 Answers 2

2

Your are passing the string "jorge" rather than the variable jorge. To pass a variable you need to wrap it in curly brackets:

<Scene
    key="sceneTwo"
    component={componentItem}
    title={content.title}
    item={jorge}
 />
Sign up to request clarification or add additional context in comments.

Comments

-1

Assuming that variable jorje is within the scope of the of the usage of eval, this should work:

 console.log(eval(this.props.item))

Here is a sample use of eval with an abbreviated object containing your values:

const jorje = "This is some output";

var scene = {key:'sceneTwo', item:'jorje'};

console.log( scene.item ); // outputs jorje

console.log( eval( scene.item ));  //outputs This is some output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.