reorganizes the code, introduces preference slice

This commit is contained in:
ajaythapliyal
2023-02-18 00:58:04 +05:30
parent 350ccad077
commit cb50795ac1
14 changed files with 45 additions and 78 deletions

View File

@@ -0,0 +1,29 @@
import { createSlice } from '@reduxjs/toolkit';
import store from '../store';
interface Preference {
apiKey: string;
}
const initialState: Preference = {
apiKey: '',
};
export const prefSlice = createSlice({
name: 'preference',
initialState,
reducers: {
setApiKey: (state, action) => {
state.apiKey = action.payload;
},
},
});
export const { setApiKey } = prefSlice.actions;
export default prefSlice.reducer;
type RootState = ReturnType<typeof store.getState>;
export const selectApiKey = (state: RootState) => state.preference.apiKey;
export const selectApiKeyStatus = (state: RootState) =>
!!state.preference.apiKey;