Chris Wilson Chris Wilson - 1 year ago 101
Javascript Question

Interpolating a JavaScript expression into an object which is a React prop

I have the following code which doesn't work, (tab) => (
<Tab options={{'option':{tab.key === 'value'}}}>

My problem is
, which is throwing an error because I'm obviously not interpolating this expression properly.

Can anyone tell me what I need to do please? I can't do it in a separate expression because the
is dependant on the
being mapped over.

Answer Source

This is not valid syntax for an object literal. Also, assuming that tabs is an iterable, the first parameter of map() should be the mapping function.

The following should work: => (
    <Tab options={{option: tab.key === 'value'}}>

To make it cleaner, define your options before rendering the component: => {
    const options = {option: tab.key === 'value'};

    return (
        <Tab options={options}>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download