Skip to content

Commit

Permalink
Merge pull request #171 from heluxjs/doc
Browse files Browse the repository at this point in the history
doc: change useDerived demo
  • Loading branch information
fantasticsoul authored Oct 25, 2024
2 parents c95eb1f + b742250 commit cf6de76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/docs/api/hooks/use-derived.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ order: 3
*/
import { atomx, derive, useDerived } from 'helux';

const { state, reactiveRoot } = atomx(1);
const result = derive(() => state.val + 100);
const { stateRoot, reactiveRoot } = atomx(1);
const result = derive(() => stateRoot.val + 100);

const change = () => {
reactiveRoot.val += 1;
Expand Down Expand Up @@ -48,9 +48,9 @@ export default () => (
import { atomx, derive, useDerived } from 'helux';

const delay = (ms = 1000) => new Promise((r) => setTimeout(r, ms));
const { state, reactiveRoot } = atomx(1);
const { stateRoot, reactiveRoot } = atomx(1);
const result = derive({
deps: () => [state.val],
deps: () => [stateRoot.val],
fn: () => 0,
task: async ({ input }) => {
await delay(100);
Expand Down
4 changes: 3 additions & 1 deletion packages/helux-core/src/factory/creator/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ function syncerFn(keyPath: string[], internal: TInternal) {
const dataSyncerCahce = new Map<string, Fn>();
/**
* 注意 syncer 只能同步一层key的数据,如需要同步多层的,使用 sync 函数
* ```jsx
* <div onClick={syncer.a}></div>
* ```
* @return syncerBuilder
*/
export function createSyncerBuilder(internal: TInternal) {
Expand All @@ -95,7 +97,7 @@ const syncFnCahce = new Map<string, Fn>();

/**
* @example
* ```
* ```jsx
* <div onClick={sync(t=>t.a.b)}></div>
* // 这里 val 将获得类型提示
* <div onClick={to(t=>t.a.b, val=>val+1)}></div>
Expand Down

0 comments on commit cf6de76

Please sign in to comment.