azinit / learn-frontend

Study examples during learning and exploring last frontend tools, libs, solutions.
2 stars 0 forks source link

Learn more: react hooks #11

Closed azinit closed 4 years ago

azinit commented 4 years ago
azinit commented 4 years ago

Как декомпозировали логику до хуков?

azinit commented 4 years ago

Цель хуков

  1. Разделить логику от UI

  2. Hooks нацелены на решение всех этих проблем, позволяя вам писать функциональные компоненты, которые имеют доступ к state, context, методам жизненного цикла, ref и т. д., без написания классов.

  3. Хуки позволяют вам повторно использовать логику состояния, не затрагивая дерево компонентов

Решаемые проблемы

src: https://medium.com/@nazrhan.mohcine/react-hooks-why-what-and-pros-vs-cons-6d3fe18b8a0a

azinit commented 4 years ago

Библиотеки/коллекции хуков

azinit commented 4 years ago

Правила хуков

Плагин: https://www.npmjs.com/package/eslint-plugin-react-hooks

azinit commented 4 years ago

Как методы жизненного цикла соответствуют хукам?

image

azinit commented 4 years ago

Тестирование

react-hooks-testing-library

Manual approach

azinit commented 4 years ago

Community hooks (top interested)

All hooks: https://usehooks.com

src: https://www.robinwieruch.de/react-hooks-fetch-data

  • useFetchApi

image

azinit commented 4 years ago

Преимущества

src: https://blog.bitsrc.io/simple-code-reuse-with-react-hooks-432f390696bf src: https://medium.com/@nazrhan.mohcine/react-hooks-why-what-and-pros-vs-cons-6d3fe18b8a0a

Недостатки

src: https://medium.com/@mateuszroth/react-hooks-advantages-and-comparison-to-older-reusable-logic-approaches-in-short-f424c9899cb5 src: https://www.reddit.com/r/reactjs/comments/9suobg/why_the_hate_for_react_hooks/ src: https://medium.com/ackee/what-i-dont-like-about-react-hooks-e6ec7da863d5 src: https://blog.logrocket.com/frustrations-with-react-hooks/

azinit commented 4 years ago

Про использование

- useNavItem
+ useLocalStorage

src: https://levelup.gitconnected.com/5-ways-to-simplify-your-react-hooks-fbedb406eee0