An open API service indexing awesome lists of open source software.

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.

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