26
ahooks 3.0 is coming! a high-quality and reliable React Hooks library!
Since the first version of ahooks (umi hooks) was released in August 2019, it has undergone 2 years of development. and has been recognized by many developers in the community. The current achievements of ahooks 2.0 mainly include:
In the development process of the past two years, with a deeper understanding of React Hooks, we can see many deficiencies in the design of ahooks 2.0. In this context, we decided to develop version 3.0.
The goal of ahooks 3.0 is to build a high-quality and reliable React Hooks library. We hope to become a stable and fundamental dependency like lodash. Compared with 2.0, it has the following advantages:
React Hooks generally encounter two problems, "DOM/BOM missing" and "useLayoutEffect warning" in SSR scenarios. ahooks v3.0 completely solves these two problems, and you can safely use ahooks in SSR scenarios with no worries.
For more information, please refer to "React Hooks & SSR"
useRequest is the Hook with the highest usage of ahooks and also the Hook with the most issues. The biggest problem of the previous useRequest is:
ahooks v3.0 completely rewrote useRequest:
For more information, please refer to "New useRequest"
ahooks v3 tries its best to help everyone avoid the closure problem by specially processing the input and output functions. I think this ability is a more radical aspect of ahooks, but it does provide users with a very good experience.
1.All the output functions of ahooks, the references are stable
const [state, setState] = useState();
As we all know, the reference of the
All functions returned by ahooks v3.0 Hooks have the same characteristics as
setState
function returned by React.useState
is fixed, and there is no need to consider weird problems when using it, and there is no need to put setState
in the dependencies of other Hooks.All functions returned by ahooks v3.0 Hooks have the same characteristics as
setState
, the reference will not change, just feel free to use it.
2.For all user input functions, always use the latest one
For the received function, ahooks v3 will do a special process to ensure that the function called each time is always the latest.
const [state, setState] = useState();
useInterval(() => {
console.log(state);
}, 1000);
For example, in the above example, the function called by
useInterval
at any time is always the latest, that is, the state
is always the latest.For more information, please refer to "ahooks function specification"
For more changes, please refer to "v2 to v3"
The slogan of ahooks v3.0 is "a high-quality and reliable React Hooks library". This is also the goal for ahooks. Hope ahooks will become one of the essential fundamental libraries in everyone's toolkit.
Thanks to the contributors and users of ahooks! Welcome to try v3.0!
Thanks to the contributors and users of ahooks! Welcome to try v3.0!
$ npm install --save ahooks@next
# or
$ yarn add ahooks@next
26