Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/hooks/src/useToggle/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ describe('useToggle', () => {
});

test('test on methods', async () => {
const hook = renderHook(() => useToggle('Hello'));
expect(hook.result.current[0]).toBe('Hello');
const hook = renderHook(() => useToggle(true));
expect(hook.result.current[0]).toBeTruthy();
callToggle(hook);
expect(hook.result.current[0]).toBeFalsy();
act(() => {
hook.result.current[1].setLeft();
});
expect(hook.result.current[0]).toBe('Hello');
expect(hook.result.current[0]).toBeTruthy();
act(() => {
hook.result.current[1].setRight();
});
Expand Down
10 changes: 4 additions & 6 deletions packages/hooks/src/useToggle/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ A hook that toggle states.
```typescript
const [state, { toggle, set, setLeft, setRight }] = useToggle(defaultValue?: boolean);

const [state, { toggle, set, setLeft, setRight }] = useToggle<T>(defaultValue: T);

const [state, { toggle, set, setLeft, setRight }] = useToggle<T, U>(defaultValue: T, reverseValue: U)
```

### Params

| Property | Description | Type | Default |
| ------------ | --------------------------- | ---- | ------- |
| defaultValue | The default value. Optional | `T` | `false` |
| reverseValue | The reverse value. Optional | `U` | - |
| Property | Description | Type | Default |
| ------------ | --------------------------- | -------------- | ------- |
| defaultValue | The default value. Optional | `boolean \| T` | `false` |
| reverseValue | The reverse value. Optional | `U` | - |

### Result

Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useToggle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export interface Actions<T> {
toggle: () => void;
}

function useToggle<T = boolean>(): [boolean, Actions<T>];
function useToggle(): [boolean, Actions<boolean>];

function useToggle<T>(defaultValue: T): [T, Actions<T>];
function useToggle(defaultValue: boolean): [boolean, Actions<boolean>];

function useToggle<T, U>(defaultValue: T, reverseValue: U): [T | U, Actions<T | U>];

Expand Down
10 changes: 4 additions & 6 deletions packages/hooks/src/useToggle/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ nav:
```typescript
const [state, { toggle, set, setLeft, setRight }] = useToggle(defaultValue?: boolean);

const [state, { toggle, set, setLeft, setRight }] = useToggle<T>(defaultValue: T);

const [state, { toggle, set, setLeft, setRight }] = useToggle<T, U>(defaultValue: T, reverseValue: U);
```

### Params

| 参数 | 说明 | 类型 | 默认值 |
| ------------ | ------------------------ | ---- | ------- |
| defaultValue | 可选项,传入默认的状态值 | `T` | `false` |
| reverseValue | 可选项,传入取反的状态值 | `U` | - |
| 参数 | 说明 | 类型 | 默认值 |
| ------------ | ------------------------ | -------------- | ------- |
| defaultValue | 可选项,传入默认的状态值 | `boolean \| T` | `false` |
| reverseValue | 可选项,传入取反的状态值 | `U` | - |

### Result

Expand Down
Loading