美文网首页
React Hook

React Hook

作者: _delong | 来源:发表于2021-04-21 11:10 被阅读0次

Through 4 questions introduce React Hook

What is Hook?

In computer programming, programmers use a technique to modify or extend the behavior of applications, operating systems or of other software components through intercepting calls or messages or events occurring within such components. Code which is used to perform intercepting such call messages or events is called hook. [1]

Hook is an kind of mechanism, and these functions which adopt the mechanism is called hook functions, and also those functions often named xxx hooks. So Hook is polysemous including 3 meaning: a mechanism, a function category, function names.

Why Hook is important?

Hooks has advantages like:

  1. Allow developer change the behavior of a program.
  2. Allow add new functionalities to application.
  3. Ensure inner consistence of application.

and, compare other programming skills, Hook follows OCP [2], there for Hook is a programming best practice.

In React, they have some other considerations around developer(React has an outstanding goodness, they care about people more than others):

  1. Reuse inside logic of component, with out modify component structure like high order component.
  2. Make it easy to understand complex component by split a big class into many function component. (I doubt that, it's bad both to build a huge class and many code pieces.)
  3. Function component has more readability for both people and machine. (So, Java developers, how do you think?)

How many Hooks there are in React?

All Hooks in react has a common name prefix: "use", like "useState", "useEffect", and if you create a custom Hook, you should also follow this habit.

Basic Hooks

Additional Hooks

Remmber: React Hook is not a pure function, they have states.

Communication has contribute other Hooks, like https://ahooks.js.org/

Which scenario that the Hooks suit for?

// TODO

References

[1] https://www.calltutors.com/blog/what-is-hook/
[2] https://en.wikipedia.org/wiki/Open-closed_principle
[3] https://reactjs.org/docs/hooks-intro.html

相关文章

  • React hook 10种 Hook

    React hook 10种 Hook (详细介绍及使用) React Hook是什么?React官网是这么介绍的...

  • 学习react hook的总结

    react16推出了react hook,react hook使得functional组件拥有了class组件的一...

  • react-hook-form使用

    官网地址:https://react-hook-form.com/[https://react-hook-form...

  • react hook介绍

    react hook是什么 react hook是react中引入新特性,它可以让react函数组件也拥有状态;通...

  • React Hook介绍与使用心得

    关于React Hook React Hook 对于React来说无疑是一个伟大的特性,它将React从类组件推向...

  • React Hook

    Through 4 questions introduce React Hook What is Hook? In...

  • react-hook

    react-hook

  • react hook入门

    一、react hook介绍 Hook 是 React 16.8 的新增特性。它可以让你在不编写 class 的情...

  • React Hooks - 学习笔记

    React Hooks Hook 是能让你在函数组件中“钩入” React 特性的函数。 State Hook u...

  • Hook

    hook 介绍 Hook 是 React16.8 的新特性。Hook 就是 JavaScript 函数, 它可以让...

网友评论

      本文标题:React Hook

      本文链接:https://www.haomeiwen.com/subject/fyealltx.html