soapbox/store/configureStore --> soapbox/store, add custom Hooks
This commit is contained in:
parent
a91fe1db91
commit
a801a8a7c8
5 changed files with 30 additions and 23 deletions
|
@ -27,7 +27,7 @@ import { INTRODUCTION_VERSION } from '../actions/onboarding';
|
||||||
import { preload } from '../actions/preload';
|
import { preload } from '../actions/preload';
|
||||||
import ErrorBoundary from '../components/error_boundary';
|
import ErrorBoundary from '../components/error_boundary';
|
||||||
import UI from '../features/ui';
|
import UI from '../features/ui';
|
||||||
import configureStore from '../store/configureStore';
|
import { store } from '../store';
|
||||||
|
|
||||||
const validLocale = locale => Object.keys(messages).includes(locale);
|
const validLocale = locale => Object.keys(messages).includes(locale);
|
||||||
|
|
||||||
|
@ -39,8 +39,6 @@ const isInstanceLoaded = state => {
|
||||||
return v !== '0.0.0' || fetchFailed;
|
return v !== '0.0.0' || fetchFailed;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const store = configureStore();
|
|
||||||
|
|
||||||
// Configure global functions for developers
|
// Configure global functions for developers
|
||||||
createGlobals(store);
|
createGlobals(store);
|
||||||
|
|
||||||
|
|
1
app/soapbox/hooks/index.ts
Normal file
1
app/soapbox/hooks/index.ts
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export { useAppSelector } from './useAppSelector';
|
5
app/soapbox/hooks/useAppSelector.ts
Normal file
5
app/soapbox/hooks/useAppSelector.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { TypedUseSelectorHook, useSelector } from 'react-redux';
|
||||||
|
|
||||||
|
import { RootState } from 'soapbox/store';
|
||||||
|
|
||||||
|
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;
|
23
app/soapbox/store.ts
Normal file
23
app/soapbox/store.ts
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import { composeWithDevTools } from '@redux-devtools/extension';
|
||||||
|
import { createStore, applyMiddleware } from 'redux';
|
||||||
|
import thunk from 'redux-thunk';
|
||||||
|
|
||||||
|
import errorsMiddleware from './middleware/errors';
|
||||||
|
import soundsMiddleware from './middleware/sounds';
|
||||||
|
import appReducer from './reducers';
|
||||||
|
|
||||||
|
export const store = createStore(
|
||||||
|
appReducer,
|
||||||
|
composeWithDevTools(
|
||||||
|
applyMiddleware(
|
||||||
|
thunk,
|
||||||
|
errorsMiddleware(),
|
||||||
|
soundsMiddleware(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Infer the `RootState` and `AppDispatch` types from the store itself
|
||||||
|
// https://redux.js.org/usage/usage-with-typescript
|
||||||
|
export type RootState = ReturnType<typeof store.getState>;
|
||||||
|
export type AppDispatch = typeof store.dispatch;
|
|
@ -1,20 +0,0 @@
|
||||||
import { composeWithDevTools } from '@redux-devtools/extension';
|
|
||||||
import { createStore, applyMiddleware } from 'redux';
|
|
||||||
import thunk from 'redux-thunk';
|
|
||||||
|
|
||||||
import errorsMiddleware from '../middleware/errors';
|
|
||||||
import soundsMiddleware from '../middleware/sounds';
|
|
||||||
import appReducer from '../reducers';
|
|
||||||
|
|
||||||
export default function configureStore() {
|
|
||||||
return createStore(
|
|
||||||
appReducer,
|
|
||||||
composeWithDevTools(
|
|
||||||
applyMiddleware(
|
|
||||||
thunk,
|
|
||||||
errorsMiddleware(),
|
|
||||||
soundsMiddleware(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
Reference in a new issue