Set everything up to use hooks for reduc actions and state

This commit is contained in:
Alejandro Celaya
2025-11-14 08:24:58 +01:00
parent ffc8249c22
commit e9951e95a9
16 changed files with 79 additions and 78 deletions

View File

@@ -3,6 +3,9 @@ import { createSlice } from '@reduxjs/toolkit';
import { mergeDeepRight } from '@shlinkio/data-manipulation';
import { getSystemPreferredTheme } from '@shlinkio/shlink-frontend-kit';
import type { Settings, ShortUrlsListSettings } from '@shlinkio/shlink-web-component/settings';
import { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import type { ShlinkState } from '../../container/types';
import type { Defined } from '../../utils/types';
type ShortUrlsOrder = Defined<ShortUrlsListSettings['defaultOrdering']>;
@@ -41,3 +44,11 @@ const { reducer, actions } = createSlice({
export const { setSettings } = actions;
export const settingsReducer = reducer;
export const useSettings = () => {
const dispatch = useDispatch();
const setSettings = useCallback((settings: Settings) => dispatch(actions.setSettings(settings)), [dispatch]);
const settings = useSelector((state: ShlinkState) => state.settings);
return { settings, setSettings };
};