build-plugin-ice-store
v2.0.11
Published
builtin `@ice/store` in icejs
Downloads
887
Keywords
Readme
plugin-store
builtin icestore
in icejs
Usage
Directory structure
src
├── models // global models
│ └── user.ts
└── pages
├── About
│ ├── index.tsx
│ └── model.ts // single model
├── Dashboard
│ ├── analysis.tsx
│ ├── index.tsx
│ └── models // multi models
│ ├── modelA.ts
│ └── modelB.ts
└── index.tsx
Define a model
// src/models/user.ts
export default {
state: {
user: {}
},
actions: {
getUserInfo: async () => {}
}
};
With Component
import { store } from 'ice/Home'
const View = () => {
const [state, actions] = store.useModel('user')
// do something...
}
Config
Set global initialstates
to src/app.ts
:
import { runApp } from 'ice'
const appConfig = {
// Set global initialstates
store: {
initialStates: {}
}
}
Set page initialstates
to src/pages/*/index.tsx
:
const HomePage = () => {
return (
<>
<h2>HomePage</h2>
</>
)
}
HomePage.pageConfig = {
// Set page initialstates
initialstates: {}
}