I have a react app with an array formatted like so:
var themes = [
{
id: 1,
name: 'Light',
},
{
id: 2,
name: 'Dark',
}
];
I have a method inside my React Component that adds a new item to the theme using overrides:
addTheme = (theme) => {
const base = themes.find(t => t.name.toLowerCase() === theme.base.toLowerCase());
var newTheme = base ? base : themes[0];
console.log(newTheme);
newTheme.id = themes[themes.length - 1].id + 1;
newTheme.name = theme.name;
themes.push(newTheme);
console.log('themes:', themes);
};
The issue I am getting is that setting the newTheme variable to the base seems to overwrite the base object in the array.
So if I am adding a theme named Midnight, the Dark theme gets changed also?
