Answer the question
In order to leave comments, you need to log in
How to return the value of the added element?
I have such a structure.
event in view
onAddLevelNode = e => {
e.preventDefault();
const { addLevelNode, node : {id} } = this.props;
addLevelNode(id, '', '');
};
export const addLevelNode = (id, key, value) => {
return {
type: ADD_LEVEL_NODE,
id,
key,
value
}
};
case ADD_LEVEL_NODE:
const addLevelNode = structure => {
const { id, value, key } = action;
const nodeId = Object.keys(structure).length;
structure[nodeId] = {
id: nodeId,
key: key,
value: value,
type: 'string',
childIds: []
};
structure[id].value = false;
structure[id].type = 'object';
structure[id].childIds.push(nodeId);
return structure;
};
return {
...state,
structure: addLevelNode(state.structure)
};
Answer the question
In order to leave comments, you need to log in
To get an element - use ref :
This is how you get it - then do what you want.)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question