-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
solution #1573
base: master
Are you sure you want to change the base?
solution #1573
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done 🔥
const USER_ID = 0; | ||
export const App: FC = () => { | ||
const [todos, setTodos] = useState<Todo[]>([]); | ||
const [errorMessage, setErrorMessage] = useState<ErrorMessage | null>(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u don't need null
for this state.
ErrorMessage.default = ''
const [errorMessage, setErrorMessage] = useState<ErrorMessage | null>(null); | |
const [errorMessage, setErrorMessage] = useState<ErrorMessage>(ErrorMessage.Default); |
(async () => { | ||
try { | ||
setTodos(await getTodos()); | ||
} catch (err) { | ||
setErrorMessage(ErrorMessage.LoadError); | ||
} | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- will be better, right?
-
- It is better to move all
useEffect
to the bottom(before render), for better support, and readability
- It is better to move all
(async () => { | |
try { | |
setTodos(await getTodos()); | |
} catch (err) { | |
setErrorMessage(ErrorMessage.LoadError); | |
} | |
})(); | |
const getAllTodos = async () => { | |
try { | |
setTodos(await getTodos()); | |
} catch (err) { | |
setErrorMessage(ErrorMessage.LoadError); | |
} | |
} | |
getAllTodos(); |
|
||
const activeTodosQuantity = useMemo(() => activeTodos.length, [activeTodos]); | ||
|
||
const addNewTodoHandler = async (title: string) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useCallback?
|
||
type Props = { | ||
filterValue: StatusFilter; | ||
setFilterValue: Dispatch<SetStateAction<StatusFilter>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u can use another syntax(up to u)
setFilterValue: Dispatch<SetStateAction<StatusFilter>>; | |
setFilterValue: (filterValue: StatusFilter) => void; |
return ( | ||
<a | ||
key={value} | ||
href={`#/${value === StatusFilter.All ? '' : value}`} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more readable
href={`#/${value === StatusFilter.All ? '' : value}`} | |
href={`#/${value !== StatusFilter.All && value}`} |
DEMO LINK