~firefoxreact-appvite-appsrcreduxwindowSize
1 itemDownload ./*

..
windowSizeSlice.ts


windowSizewindowSizeSlice.ts
768 B• 3•  3 days ago•  DownloadRawClose
3 days ago•  3

{}
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
©twily.info 2013 - 2025
twily at twily dot info



2 274 775 visits
... ^ v