Creating your own hook . The design of Hooks isn't tied to React. You may have been surprised by the Rules of Hooks . And that's why I'm personally excited about Hooks . Each Hook may contain some local state and side effects.
All in all, you don't have to learn the hooks system now. 也许你在想React在哪里保存了Hooks 的状态。 Perhaps you're wondering where React keeps the state for Hooks . Note that there is no“magic” in the implementation of Hooks either. 在我们看来,自定义Hooks是Hooks 提案中最吸引人的部分。 Custom Hooks are, in our opinion, the most appealing part of the Hooks proposal. 杀死Hooks 家族的卡车司机被指控犯有过失杀人罪。 The driver of the truck that killed the Hooks family was charged with negligent homicide.我们为每个组件保留了一个Hooks列表,并在每次Hooks 被调用时移动到列表中的下一项。 We keep a list of Hooks per component, and move to the next item in the list whenever a Hook is used. 不过,花费一个小时看视频也是时间上的巨大投入,所以我决定在下面分享一些关于Hooks 的想法。 However, even an hour is a big time investment, so I decided to share a few thoughts on Hooks below. 这就是Hooks 的目的--使组件做到真正的声明式,即使它们包含状态和副作用。 And that's the goal of Hooks - to make components truly declarative even if they contain state and side effects. React提供了一些内置的Hooks ,它们暴露了React的“构建块”:状态、生命周期和上下文。 React provides a few built-in Hooks exposing the“building blocks” of React: state, lifecycle, and context. Hooks 非常新,在考虑学习或采用它们之前等待更多示例和教程可能会更好。Hooks are very new, and it might be better to wait for more examples and tutorials before considering learning or adopting them. 就部署大小而言,对Hooks 的支持仅仅增加了React约1.5kB(min+gzip)的大小。 In terms of the implementation size, the Hooks support increases React only by~1.5kB(min+gzip). 我强烈推荐大家观看这个开场演讲,在这个演讲里,大家可以了解到我们尝试使用Hooks 提案去解决的问题。 I strongly recommend to watch this opening keynote to see the problems we're trying to solve with the Hooks proposal. 为了更好地理解AsyncHooks 是什么,让我们退后一步,先掌握继续本地存储。 To better understand what Async Hooks are, let's take a step back and get to grips with continuation-local storage first. Hooks 在组件内部应用React的哲学(显式数据流和组合),而不仅仅是组件之间。Hooks apply the React philosophy(explicit data flow and composition) inside a component, rather than just between the components. 但是如果React社区接受了Hooks ,那么同时推荐两种不同的方式来编写组件是没有意义的。 But if the React community embraces Hooks , it doesn't make sense to have two different recommended ways to write components. Hooks 可以使得你始终使用函数,而不必在函数、类、高阶组件和reader属性之间不断切换。Hooks let you always use functions instead of having to constantly switch between functions, classes, higher-order components, and render props. 在我们详细介绍Hooks 之前,你可能会担心我们通过Hooks只是向React添加了更多概念。 Before we look at Hooks in detail, you might be worried that we're just adding more concepts to React with Hooks. . 相反,Hooks 为您已经知道的React概念提供了更直接的API:props,state,context,refs和lifecycle。 Instead, Hooks provide a more direct API to the React concepts you already know: props, state, context, refs, and lifecycle. 如果React社区接受Hooks 的提案,这将减少编写React应用时需要考虑的概念数量。 If the React community embraces the Hooks proposal, it will reduce the number of concepts you need to juggle when writing React applications. Hooks 目录包含客户端或服务端的钩子脚本(hookscripts),在Git钩子中这部分话题已被详细探讨过。The hooks directory contains your client- or server-side hook scripts, which are discussed in detail in Git Hooks. . 我们打算让Hooks 涵盖所有现有的类用例,但我们将在可预见的未来继续支持类组件。 We intend for Hooks to cover all existing use cases for classes, but we will keep supporting class components for the foreseeable future. Hooks 是完全封装的--你每次调用Hooks 函数,它都会从当前执行组件中获取到独立的本地状态。Hooks are fully encapsulated- each time you call a Hook , it gets isolated local state within the currently executing component.与此同时,如果你能够尝试16.7alpha版并在Hooks proposal和reportanybugs向在我们提供反馈,我们将不胜感激。 We would appreciate if you could experiment with the 16.7 alpha to provide us with feedback on the Hooks proposal and report any bugs. 十月,JohnHooks 被任命为GiorgioArmani日本的新主席,Armani先生本人继续担任该集团的商务总监。 In October, John Hooks was appointed the new President of Giorgio Armani Japan and Giorgio Armani continued as commercial director of the group. 由于Hooks 是普通的JavaScript函数,因此你可以将React提供的内置Hooks 组合到你自己的“自定义Hooks ”中。 Since Hooks are regular JavaScript functions, you can combine built-in Hooks provided by React into your own“custom Hooks ”.
Display more examples
Results: 112 ,
Time: 0.0268