Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 3b8a794

Browse files
committed
added types to Rex
1 parent 9004e4b commit 3b8a794

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,19 @@ export const RexProvider = ({ children, store }: RexProviderProps) => {
3636
return <Provider value={initializedStore}>{children}</Provider>;
3737
};
3838

39-
class Rex {
40-
private internalState: object;
41-
private updateInternalState: Dispatch<SetStateAction<object>>;
39+
class Rex<S> {
40+
private internalState!: Readonly<S>;
41+
private updateInternalState!: Dispatch<SetStateAction<S>>;
4242

43-
get state() {
43+
public get state(): Readonly<S> {
4444
return this.internalState;
4545
}
4646

47-
set state(value: object) {
48-
[this.internalState, this.updateInternalState] = useState<object>(value);
47+
public set state(value: Readonly<S>) {
48+
[this.internalState, this.updateInternalState] = useState<S>(value);
4949
}
5050

51-
public setState(newInternalState: object) {
51+
public setState<K extends keyof S>(newInternalState: Pick<S, K> | S): void {
5252
if (!this.internalState) {
5353
this.state = newInternalState;
5454
} else {

0 commit comments

Comments
 (0)