请问 app.js 中注入的 Context,为何只更新使用 Context 的组件? #9448
Unanswered
nanxiaobei
asked this question in
Q & A
Replies: 2 comments
-
这个应该是react的能力吧 |
Beta Was this translation helpful? Give feedback.
0 replies
-
@nanxiaobei 把 JSX 展开为 例子一
const Home = () => (
h(HomeContext.Provider, {}, [
h(A)
h(B)
])
) 例子二
又根据 const App = () => (
h(HomeContext.Provider, {}, this.props.children)
) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
这个问题不太好描述,大概是这样。
默认在页面组件比如
pages/home.jsx
里使用 React Context:如果在 B 中更新 HomeContext,那么 Home、A、B 都将 re-render
但如果把 Context 放在 Taro 项目的
app.js
里:而在
pages/home.jsx
里只使用:此时在 B 中更新 AppContext,那么只有 App、B 会 re-render。Home 和 A 并不会 re-render。
请问这个是怎么做到的?Taro 做了什么特殊处理,实现了这个类似
react-redux
节流的效果呢?Beta Was this translation helpful? Give feedback.
All reactions