const initialState: FriendsState = {
friends: []
};
export default function friends(state = initialState, action: Action): FriendsState {
switch (action.type) {
case TYPES.ADD_TO_FRIENDS:
return assign({}, state, {
friends: state.friends.push(action.payload.friendId)
})
}
}
I am basically trying to add a friendId that looks like something like 1003 or something into my friends array. Is that the right way of going about it?
What about if I have to add an object? something like { friendId: 1003, category: 4 }
export interface Friends {
friends: FriendIds[];
};
interface FriendIds {
id: number;
}
TypeError: state.friends.push is not a functionpushdoes not return the resulting array, so in some cases you may want to useconcat.friendsto an integer (which is whatpushreturns). Then the second push will fail, because you can't push to an integer.