Code Editor
Web Browser
Learn
Components and Advanced JSX

Use a Variable Attribute in a Component

Take a look at this JavaScript object named redPanda:

const redPanda = { src: 'http://bit.ly/1U92LL3', alt: 'Red Panda', width: '200px };

How could you render a React component, and get a picture with redPanda's properties?

Select RedPanda.js to see one way to do it.

Note all of the curly-brace JavaScript injections inside of the render function! Lines 16, 17, and 18 all use JavaScript injections.

You can, and often will, inject JavaScript into JSX inside of a render function.

Report a Bug
If you see a bug or any other issue with this page, please report it here.