https://github.com/afeiship/rtk-config-store
Redux toolkit config store with next.
https://github.com/afeiship/rtk-config-store
config global redux rtk state store toolkit
Last synced: about 2 months ago
JSON representation
Redux toolkit config store with next.
- Host: GitHub
- URL: https://github.com/afeiship/rtk-config-store
- Owner: afeiship
- License: mit
- Created: 2021-04-17T14:46:41.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-28T09:13:35.000Z (almost 2 years ago)
- Last Synced: 2025-05-22T22:10:08.605Z (about 1 year ago)
- Topics: config, global, redux, rtk, state, store, toolkit
- Language: TypeScript
- Homepage: https://js.work/works/9ef82b41cca4f
- Size: 55.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# rtk-config-store
> Redux toolkit config store with next.
[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]
## installation
```shell
npm install @jswork/rtk-config-store
```
## usage
> store.ts
```ts
import { scanWebpack } from '@jswork/scan-modules';
import RtkConfigStore from '@jswork/rtk-config-store';
// when webpack
const context = require.context('./modules', true, /\.ts$/);
const modules = scanWebpack(context, { modules: '/modules/' });
export const store = RtkConfigStore({ modules, preloadedState: {}, reducer: {} });
// Infer the `RootState` and `AppDispatch` types from the store itself
export type RootState = ReturnType;
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState}
export type AppDispatch = typeof store.dispatch;
```
> app.ts
```ts
import { Provider } from 'react-redux';
import { store } from '@/shared/stores/root';
interface IReduxProviderProps extends React.PropsWithChildren {}
export default function (props: IReduxProviderProps) {
const { children } = props;
return {children};
}
```
> define a slice use `nx.$createSlice`
```ts
export default nx.$createSlice({
name: 'user',
initialState: {
token: null,
profile: JSON.parse(localStorage.getItem('profile'))
},
reducers: {
setToken: (state, action) => {
state.token = action.payload;
},
setProfile: (state, action) => {
state.profile = action.payload;
}
},
watch: {
profile: (newValue, oldValue, objectPath) => {
console.log('profile:', newVal, oldVal, objectPath);
}
}
});
```
## types
```ts
///
```
## license
Code released under [the MIT license](https://github.com/afeiship/rtk-config-store/blob/master/LICENSE.txt).
[version-image]: https://img.shields.io/npm/v/@jswork/rtk-config-store
[version-url]: https://npmjs.org/package/@jswork/rtk-config-store
[license-image]: https://img.shields.io/npm/l/@jswork/rtk-config-store
[license-url]: https://github.com/afeiship/rtk-config-store/blob/master/LICENSE.txt
[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/rtk-config-store
[size-url]: https://github.com/afeiship/rtk-config-store/blob/master/dist/index.min.js
[download-image]: https://img.shields.io/npm/dm/@jswork/rtk-config-store
[download-url]: https://www.npmjs.com/package/@jswork/rtk-config-store