Skip to content

3 React: Routing and Hooks#3

Open
wingedseraph wants to merge 21 commits into
unit-testingfrom
hooks-and-routing
Open

3 React: Routing and Hooks#3
wingedseraph wants to merge 21 commits into
unit-testingfrom
hooks-and-routing

Conversation

@wingedseraph

@wingedseraph wingedseraph commented Jul 26, 2025

Copy link
Copy Markdown
Owner
  1. Task: link
  2. Screenshot:
image image
  1. deploy

  2. Done 27.07.2025 / deadline 28.07.2025

  3. Score: 100/100

  • Custom hook to restore search query from LS - 20
  • Pagination is present in both URL and on the page - 20
  • Upon clicking, open details panel on the right side of the page: - 5
    • Use router outlet, left side of the page should continue displaying the list of results - 10
    • Initiate an additional API call, display a loader, and update the URL - 10
    • Details panel should be closed either on the "close" button click or on the main panel click - 10
  • About page is implemented with author information and a link to the RS School React course - 5
  • 404 is implemented - 5
  • New tests are added for the new functionality - 15

@wingedseraph wingedseraph changed the title React: Routing and Hooks 3 React: Routing and Hooks Aug 3, 2025

@ChocolateNao ChocolateNao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошая работа, молодец!

Comment thread src/hooks/useLocalStorage.ts
Comment thread src/config/routesConfig.ts
Comment thread src/layout/layout.tsx
Comment on lines +19 to +21
<Suspense fallback={<Spinner />}>
<Outlet />
</Suspense>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь не ошибка, просто рекомендации/наблюдение на что обратить внимание. У тебя тут, вроде, все нормально.

Очень часто начинающие React-разработчики неправильно используют Suspense. Сам по себе он не работает, о чем часто забывают и пихают его в проект.

Only Suspense-enabled data sources will activate the Suspense component. They include:
Data fetching with Suspense-enabled frameworks like Relay and Next.js
Lazy-loading component code with lazy
Reading the value of a cached Promise with use

@wingedseraph wingedseraph Aug 11, 2025

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Часть с роутером я взял из нашей командого проекта, я там занимался роутингом, насколько я понял: Suspense взаимодействует с React.lazy загрузкой компонентов, как раз у меня каждый компонент подгружается через - Component: lazy(() => import('@/pages/index/index')), тем самым Suspense работает

по крайней мере, в командой работе Suspense был заметнее - ведь страницы тяжелее, пока они загрузятся на мгновение-секунду появлялся Spinner

Comment thread src/pages/index/index.tsx
Comment on lines +26 to +29
useEffect(() => {
const page = pageId ? Number(pageId) : 1;
setCurrentPokemonPage(page);
}, [pageId]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State update внутри useEffect. https://react.dev/learn/you-might-not-need-an-effect

Comment on lines +14 to +16
const response = await fetch(
`${POKEMON_BASE_API_URL}cards?name=*${query}*&image=*&pagination:page=${POKEMON_CURRENT_PAGE}&pagination:itemsPerPage=${POKEMON_PAGE_SIZE}`
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Чтобы в дальнейшем не городить длинную строчку из параметров, которая, к тому же, плохо читается, или когда (если) будут появляться опциональные параметры, можно использовать URL конструктор. Там есть удобные методы для работы с параметрами и самим адресом.

Comment on lines +17 to +18
console.error('fetchPokemon:', error);
data = error;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эта ошибка дальше в компоненте нигде не обрабатывается. У тебя не будет тут null никогда, а типы говорят обратное.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants