zustand-utils
Advanced tools
Comparing version 1.1.2 to 1.2.0
export * from './context'; | ||
export * from './createStoreUpdater'; | ||
export * from './optionalDevtools'; |
export * from "./context"; | ||
export * from "./createStoreUpdater"; | ||
export * from "./optionalDevtools"; |
{ | ||
"name": "zustand-utils", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "some utils for zustand", | ||
@@ -23,3 +23,4 @@ "keywords": [ | ||
"files": [ | ||
"es" | ||
"es", | ||
"lib" | ||
], | ||
@@ -26,0 +27,0 @@ "scripts": { |
@@ -229,4 +229,48 @@ <img src="https://gw.alipayobjects.com/zos/antfincdn/R8sN%24GNdh6/language.svg" width="18"> [English](./README.md) | 简体中文 | ||
好的,以下是 `createStoreUpdater` 的说明文档: | ||
## createStoreUpdater | ||
`createStoreUpdater` 是一个用于更新 Store 中指定 key 的值的函数。 | ||
### 参数 | ||
`createStoreUpdater` 接收一个 `StoreApi` 对象作为参数,该对象包含了一些操作 Store 的方法,如 `getState`、`setState`、`subscribe` 和 `destroy`。 | ||
`createStoreUpdater` 返回一个函数,该函数接收以下参数: | ||
- `key`:需要更新的 Store 中的 key; | ||
- `value`:需要更新的值; | ||
- `deps`:依赖项数组,默认为 `[value]`; | ||
- `setStoreState`:一个可选的回调函数,用于更新 Store 状态,默认为 `storeApi.setState`。 | ||
### 返回值 | ||
`createStoreUpdater` 返回一个函数,该函数用于更新 Store 中指定 key 的值。 | ||
### 示例 | ||
```typescript | ||
import { createStoreUpdater } from 'path/to/createStoreUpdater'; | ||
import { useStore } from 'path/to/useStore'; | ||
interface User { | ||
name: string; | ||
age: number; | ||
} | ||
const storeApi = useStore<User>({ name: '', age: 0 }); | ||
const updateUser = createStoreUpdater(storeApi); | ||
// 更新 name | ||
updateUser('name', 'John Doe'); | ||
// 更新 age | ||
updateUser('age', 18); | ||
``` | ||
在上面的示例中,我们首先使用 `useStore` 创建了一个 Store,然后使用 `createStoreUpdater` 创建了一个更新器 `updateUser`,最后通过调用 `updateUser` 来更新 Store 中的 `name` 和 `age`。 | ||
## License | ||
[MIT](./LICENSE) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29319
20
281
1