Skip to content

Commit

Permalink
Merge pull request #815 from Dolov/master
Browse files Browse the repository at this point in the history
feat: useControllableValue add more callback params
  • Loading branch information
brickspert authored Jan 10, 2021
2 parents 515f687 + 38f000f commit 2486993
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,21 @@ describe('useControllableValue', () => {
});

it('onChange should work', () => {
let extraParam: string = ''
const props = {
value: 2,
onChange(v: any) {
onChange(v: any, extra) {
this.value = v;
extraParam = extra
},
};
const hook = setUp(props);
expect(hook.result.current[0]).toEqual(2);
act(() => {
hook.result.current[1](3);
hook.result.current[1](3, 'extraParam');
});
expect(props.value).toEqual(3);
expect(extraParam).toEqual('extraParam');
});

it('test on state update', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useControllableValue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export default function useControllableValue<T>(props: Props = {}, options: Opti
}, [value, valuePropName]);

const handleSetState = useCallback(
(v: T | undefined) => {
(v: T | undefined, ...args: any[]) => {
if (!(valuePropName in props)) {
setState(v);
}
if (props[trigger]) {
props[trigger](v);
props[trigger](v, ...args);
}
},
[props, valuePropName, trigger],
Expand Down

0 comments on commit 2486993

Please sign in to comment.