Skip to content

Commit

Permalink
feat(useCounter): reset to the newest initialValue (#667)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yingtao Su authored and streamich committed Nov 10, 2019
1 parent dbf18e8 commit e653383
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/__stories__/useCounter.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { useCounter } from '..';
import ShowDocs from './util/ShowDocs';

const Demo = () => {
const [initialValue, setInitialValue] = React.useState(5);
const [min, { inc: incMin, dec: decMin }] = useCounter(1);
const [max, { inc: incMax, dec: decMax }] = useCounter(10);
const [value, { inc, dec, set, reset }] = useCounter(5, max, min);
const [value, { inc, dec, set, reset }] = useCounter(initialValue, max, min);

return (
<div>
Expand All @@ -31,6 +32,11 @@ const Demo = () => {
Max value:
<button onClick={() => incMax()}>Increment</button>
<button onClick={() => decMax()}>Decrement</button>
<br />
<br />
Initial value: {initialValue}
<button onClick={() => setInitialValue(v => ++v)}>Increment</button>
<button onClick={() => setInitialValue(v => --v)}>Decrement</button>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/useCounter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ export default function useCounter(
set(rValue);
},
};
}, [min, max]),
}, [init, min, max]),
];
}

0 comments on commit e653383

Please sign in to comment.