@lumina-study/user-settings-redux
Version:
Redux store for Lumina Study user settings with unstorage persistence
56 lines • 1.43 kB
JavaScript
import { useDispatch, useSelector } from 'react-redux';
/**
* Typed version of useDispatch hook for use throughout the app
*
* @example
* ```typescript
* const dispatch = useAppDispatch();
* dispatch(setLanguage('he'));
* ```
*/
export const useAppDispatch = useDispatch;
/**
* Typed version of useSelector hook for use throughout the app
*
* @example
* ```typescript
* const language = useAppSelector((state) => state.userSettings.language);
* ```
*/
export const useAppSelector = useSelector;
/**
* Custom hook to access user settings from the store
*
* @returns The current user settings state
*
* @example
* ```typescript
* const { language } = useUserSettings();
* ```
*/
export function useUserSettings() {
return useAppSelector(state => state.userSettings);
}
/**
* Custom hook to access and update the language setting
*
* @returns A tuple containing the current language and a setter function
*
* @example
* ```typescript
* const [language, setLang] = useLanguage();
*
* // Update language
* setLang('he');
* ```
*/
export function useLanguage() {
const language = useAppSelector(state => state.userSettings.language);
const dispatch = useAppDispatch();
const setLang = (newLanguage) => {
const { setLanguage } = require('./userSettingsSlice');
dispatch(setLanguage(newLanguage));
};
return [language, setLang];
}
//# sourceMappingURL=hooks.js.map