diff --git a/lib/store.ts b/lib/store.ts index 5dfcc38..c6afb83 100644 --- a/lib/store.ts +++ b/lib/store.ts @@ -1,5 +1,5 @@ -export const createStore = (initialState) => { - let state = initialState +export const createStore = (initialState: StateType) => { + let state: StateType = initialState const listeners = new Set<() => void>() return { diff --git a/src/components/profile/profile.tsx b/src/components/profile/profile.tsx index 35718a4..f8442ac 100644 --- a/src/components/profile/profile.tsx +++ b/src/components/profile/profile.tsx @@ -149,9 +149,8 @@ const withStars = ) } -const Counter = ({ stars, addStar, subStar, userId }) => { +const Counter = ({ stars, addStar, subStar, userId }: { userId: 'some-user-id' | '2'}) => { const { rate, setUserRate } = useUsers((state) => state[userId].rated) - console.log(userId) return (
diff --git a/src/components/stars.tsx b/src/components/stars.tsx index feeee6e..12d6e22 100644 --- a/src/components/stars.tsx +++ b/src/components/stars.tsx @@ -25,7 +25,7 @@ export const Stars = ({ userId, }: { count: number - userId: string + userId: 'some-user-id' | '2' // rated: number // setRated: (rate: number) => void }) => { diff --git a/src/hooks.ts b/src/hooks.ts index 9886aec..7cdad99 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -2,16 +2,16 @@ import { useEffect, useState, useSyncExternalStore } from 'react' import { usersStore } from './__data__/users' -export const useUsers = (selector) => { - // const [rate, setRate] = useState(selector(usersStore.getState())) +export const useUsers = (selector: (state: ReturnType) => StatePart) => { + // const [rate, setRate] = useState(selector(usersStore.getState())) - // useEffect(() => { - // const unsubscribe = usersStore.subscribe(() => { - // setRate(selector(usersStore.getState())) - // }) + // useEffect(() => { + // const unsubscribe = usersStore.subscribe(() => { + // setRate(selector(usersStore.getState())) + // }) - // return unsubscribe - // }, []) + // return unsubscribe + // }, []) const rate = useSyncExternalStore(usersStore.subscribe, () => selector(usersStore.getState()),