Skip to content

Commit 607dfd1

Browse files
committed
feat(hooks): add useState hook
1 parent b3c540a commit 607dfd1

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/__tests__/useState.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import useState from '../useState';
2+
import renderHook from '../util/renderHook';
3+
4+
describe('useState', () => {
5+
it('should be defined', () => {
6+
expect(useState).toBeDefined();
7+
});
8+
9+
it('should update state', () => {
10+
type Inject = { count1: number; count2: number };
11+
const { vm } = renderHook<Inject>(() => ({
12+
...useState({ count1: 'count' }),
13+
...useState('test', { count2: 'count' }),
14+
}));
15+
expect(vm.count1).toBe(0);
16+
expect(vm.count2).toBe(0);
17+
18+
vm.$store.commit('increment');
19+
vm.$store.commit('test/decrement');
20+
21+
expect(vm.count1).toBe(1);
22+
expect(vm.count2).toBe(-1);
23+
});
24+
});

src/useState.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import createVuexHelper, { Helper } from './util/helpers';
2+
3+
export default createVuexHelper(Helper.State);

0 commit comments

Comments
 (0)