Skip to content
Snippets Groups Projects
Select Git revision
  • 6f84221573c322af5727779b235dfbeadbaf5c0e
  • main default protected
2 results

unitSelectorSlice.js

Blame
  • Forked from SOFT Core / SOFT 260 / React Redux Starter Code
    Source project has a limited visibility.
    unitSelectorSlice.js 883 B
    import { createSlice } from '@reduxjs/toolkit';
    
    const unitSelectorSlice = createSlice({
      name: 'unitSelector',
      initialState: {
        currentInputUnit: 'km',
        currentOutputUnit: 'km',
      },
      reducers: {
        // The action payload should have the unit to switch to with the in or out
        setCurrentInputUnit: (state, action) => {
          const newUnit = action.payload;
          state.currentInputUnit = newUnit;
        },
        setCurrentOutputUnit: (state, action) => {
          const newUnit = action.payload;
          state.currentOutputUnit = newUnit;
        },
      },
    });
    export default unitSelectorSlice;
    
    export const {
      setCurrentInputUnit,
      setCurrentOutputUnit,
    } = unitSelectorSlice.actions;
    
    export function selectCurrentInputUnit(state) {
      return state.unitSelector.currentInputUnit;
    }
    
    export function selectCurrentOutputUnit(state) {
      return state.unitSelector.currentOutputUnit;
    }