import { createSlice } from '@reduxjs/toolkit';
import type { PayloadAction } from '@reduxjs/toolkit';
// Define the shape of the window size state
interface WindowSizeState {
width: number;
height: number;
}
// Initial state
const initialState: WindowSizeState = {
width: window.innerWidth,
height: window.innerHeight,
};
// Create a slice for window size
const windowSizeSlice = createSlice({
name: 'windowSize',
initialState,
reducers: {
setWindowSize: (state, action: PayloadAction<WindowSizeState>) => {
state.width = action.payload.width;
state.height = action.payload.height;
},
},
});
// Export actions
export const { setWindowSize } = windowSizeSlice.actions;
// Export reducer
export default windowSizeSlice.reducer;
Top