You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bot detected the issue body's language is not English, translate it automatically.
Title: Tiny-React Opinions on Overcoming Difficulties
Provide/Inject
$parent / $children
For a long time, Provide / Inject could not be implemented because React useContext could only be called at the top level, which meant that the context could not be obtained in statements like if. However, the current React Canary version has released the use API, whose usage is similar to Provide / Inject.
$parent / $children are still unimplementable, but in terms of code design, accessing the parent-child component itself is unreliable, because it relies on the developer following the hierarchical structure used by the component, and destroys the readability of the code (e.g. $parent.$parent) and robustness (modifying the component hierarchy causes unreliable access to $parent/$children, and directly modifying parent-child component properties violates the design pattern of state control). We can completely implement code requirements through context (Provide/Inject) or attributes (prop).
if
语句中获取上下文。但是目前 React Canary 版本发布了 use API,用法类似于 Provide / Inject。$parent.$parent
)和鲁棒性(修改组件层级导致$parent / $children的访问不可靠,直接修改父子组件属性违反了状态控制的设计模式)。我们完全可以通过上下文(Provide / Inject)或者属性(prop)的方式去实现代码需求。The text was updated successfully, but these errors were encountered: