let initialState = {
posts: [
{
id: 1,
postMessage: 'Hello world',
file: '',
},
] as Array<PostType>,
}
case 'SN/PROFILE/ADD_POST': {
let newPost = {
id: 1,
postMessage: action.post.postMessage,
file: action.post.file,
}
return {
...state,
posts: [...state.posts, newPost],
}
}
case 'SN/PROFILE/ADD_POST': {
let newPost = {
id: 1,
postMessage: action.post.postMessage,
file: action.post.file,
}
+ let previousPost = state.posts[state.posts.length - 1] || null;
+ if (previousPost !== null) {
+ newPost.id = previousPost.id + 1;
+ }
return {
...state,
posts: [...state.posts, newPost],
}
}