a bit of types

This commit is contained in:
Primakov Alexandr Alexandrovich 2024-11-12 20:18:36 +03:00
parent fd0eb66563
commit 0f211115cf
4 changed files with 12 additions and 13 deletions

View File

@ -1,5 +1,5 @@
export const createStore = (initialState) => {
let state = initialState
export const createStore = <StateType>(initialState: StateType) => {
let state: StateType = initialState
const listeners = new Set<() => void>()
return {

View File

@ -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 (
<Center>

View File

@ -25,7 +25,7 @@ export const Stars = ({
userId,
}: {
count: number
userId: string
userId: 'some-user-id' | '2'
// rated: number
// setRated: (rate: number) => void
}) => {

View File

@ -2,7 +2,7 @@ import { useEffect, useState, useSyncExternalStore } from 'react'
import { usersStore } from './__data__/users'
export const useUsers = (selector) => {
export const useUsers = <StatePart>(selector: (state: ReturnType<typeof usersStore.getState>) => StatePart) => {
// const [rate, setRate] = useState(selector(usersStore.getState()))
// useEffect(() => {