Skip to content
Snippets Groups Projects
Select Git revision
  • 32feda1635d02c1b02d8f59fbceb79af4249e777
  • main default protected
2 results

unitSelectorSlice.js

Blame
  • unitSelectorSlice.js 894 B
    import { createSlice } from '@reduxjs/toolkit';
    
    const unitSelectorSlice = createSlice({
      name: 'unitSelector',
      initialState: {
        currentInputUnit: 'in',
        currentOutputUnit: 'in',
      },
      reducers: {
        // The action payload should have the unit to switch to with the in or out
        setCurrentInputUnit: (state, action) => {
          const newUnit = action.payload;
          return {
            ...state,
            currentInputUnit: newUnit,
          };
        },
        setCurrentOutputUnit: (state, action) => {
          const newUnit = action.payload;
          return {
            ...state,
            currentOutputUnit: newUnit,
          };
        },
      },
    });
    export default unitSelectorSlice;
    
    export const {
      setCurrentInputUnit,
      setCurrentOutputUnit,
    } = unitSelectorSlice.actions;
    
    export function selectCurrentInputUnit(state) {
      return state.unitSelector.currentInputUnit;
    }