mirror of
https://github.com/NohamR/gitprofile.git
synced 2026-05-26 04:17:14 +00:00
Change theme
This commit is contained in:
23
src/store/slices/themeSlice.js
Normal file
23
src/store/slices/themeSlice.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
import { getThemeValue } from '../../helpers/utils';
|
||||
|
||||
const initialState = getThemeValue();
|
||||
|
||||
export const themeSlice = createSlice({
|
||||
name: 'theme',
|
||||
initialState: initialState,
|
||||
reducers: {
|
||||
setTheme: (state, action) => {
|
||||
state = action.payload;
|
||||
|
||||
document.documentElement.setAttribute('data-theme', state);
|
||||
localStorage.setItem('theme', state);
|
||||
|
||||
return state;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
export const { setTheme } = themeSlice.actions;
|
||||
|
||||
export default themeSlice.reducer;
|
||||
@@ -1,8 +1,10 @@
|
||||
import { combineReducers, configureStore } from '@reduxjs/toolkit';
|
||||
import profileSlice from './slices/profileSlice';
|
||||
import themeSlice from './slices/themeSlice';
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
profile: profileSlice
|
||||
profile: profileSlice,
|
||||
theme: themeSlice,
|
||||
})
|
||||
|
||||
export const store = configureStore({
|
||||
|
||||
Reference in New Issue
Block a user