ddaudiosolutions
ddaudiosolutions

Reputation: 150

Deepen inside an object dynamically

i have an object like this:

state.variationsData = {
description:"Provar altas de CAN"
examples_edit: null
examples_new: null
examples_production: "[{\"text\": \"baby\"}, {\"text\": \"bajas de CAN en 
 productivo\"}, {\"text\": \"levantar can desde local\"}, {\"text\": 
 \"salvar cambios en can\"}, {\"text\": \"borrar datos en can\"}, 
 {\"text\":\"sustituir usuarios can\"}]"
 id: "#CA2_3"
 idResponse:"CA2_3"
}

I would like to get the examples edit, new, production, with a variable, to print in my react edit form.

i have this:

const retrieveVariations = useSelector(state => 
 state.variationsData.examples_(here i would like to use a variable with 
 (new, edit, production);

I have this variable, but i don't know how to insert in the route.

I tryed:

const retrieveVariations = useSelector(state => 
state.variationsData.examples_{variable});

const retrieveVariations = useSelector(state => 
state.variationsData.examples_+variable);

const retrieveVariations = useSelector(state => state.variationsData. 
[examples_+variable]);

Some suggestion? Thanks

Upvotes: -1

Views: 48

Answers (1)

0stone0
0stone0

Reputation: 44217

Use [] to define the key, then use a base string (examples_) with your desired variable (variable)

const retrieveVariations = useSelector(state => state.variationsData['examples_' + variable]);

Upvotes: 1

Related Questions