I have a form with a submit. When it is clicked I create an object to send these data to POST.
So I have saveEntity const:
JavaScript
x
12
12
1
const saveEntity = (event, errors, values) => {
2
3
// this is the const that is signed as error:
4
const valoreComune: any = comCod ? { comCod: { comCod: comCod } } : personEntity.comCod ? { comCod: { comCod: personEntity.comCod.comCod } } : { comCod: null };
5
//....
6
7
const entity = { // this is the object that I pass to post
8
// ....
9
valoreComune
10
}
11
}
12
I need to recreate this object structure:
JavaScript
1
4
1
comCod: {
2
comCod: value
3
}
4
or
JavaScript
1
2
1
comCod: null
2
Now I receive this error:
Expected property shorthand object-shorthand
Now usually i resolve writing directly in this way:
JavaScript
1
4
1
const entity = {
2
valoreComune
3
}
4
but it doesn’t work. How can I do?
Advertisement
Answer
You should use the object-shorthand syntax for this part:
JavaScript
1
2
1
{ comCod: { comCod: comCod } }
2
Which is written like so:
JavaScript
1
2
1
{ comCod: { comCod } }
2