Hey there,
I’m building my first React-Redux project and running into an issue trying to import in a local data.js file variable called allContentTilesData
into my contentTilesSlice.js file (posted below). When I hardcode in the object for the initialState property it works fine, but when I replace it with the imported variable that should be referencing the same object it just returns the variable name as a string.
I’m guessing this is some silly syntax error I’m missing, but any help would be greatly appreciated!
import { createSlice } from '@reduxjs/toolkit';
import allContentTilesData from '../../data';
export const contentTilesSlice = createSlice({
name: 'contentTiles',
initialState: {
contentTiles: {
allContentTilesData
}
},
reducers: {
addTile: (state, action) => {
const { id } = action.payload;
state.contentTiles[id] = action.payload;
}
}
});
export const { addTile } = contentTilesSlice.actions;
export const selectContentTiles = (state) => state.contentTiles.contentTiles;
export default contentTilesSlice.reducer;