Awesome q2a theme

Why doesn't the creation of the object?

0 like 0 dislike
23 views
Why it is impossible to combine the object? That's a mistake.
5aeaef0a92f9d154547443.png
Here is the code.
const courses = (state = {}, action) => { switch (action.type) { case constants.courses.CREATE_COURSE: return { ...state action.title:{ title:action.title } } } return state; }
by | 23 views

3 Answers

0 like 0 dislike
Complement response 0xD34F - it is impossible to name properties to specify that point.

return { ...state nazvaniya:{ title:action.title } }


where is nazvaniya must be a string! If you want it to be a computed expression, you need to add (as it was already said) brackets, ie:

return { ...state [action.title]:{ title:action.title } }


But I think 99% you want something, because if you get that state title will be installed in the field with the same name, which will come into action.title, for example:

return { ...state dollar:{ title: "dollar" // suppose that in action.title string "dollar" } }


To understand the theory.

p.s. tag "functional programming" here looks too dangerous)
by
0 like 0 dislike
Most likely, your code should be like this.
const courses = (state = {}, action) => { switch (action.type) { case constants.courses.CREATE_COURSE: return { ...state [action.title]: { title:action.title } } } return state; }
by
0 like 0 dislike
Why it doesn't work - you have written a syntax error.

Take your action.title in quotation marks or in brackets, depending on what you need. In the first case, the property name will be "action.title", and the second action value.title.
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users