-
Notifications
You must be signed in to change notification settings - Fork 365
Conversation
可以在 App 里面挂载 |
应该是可以的吧?这就非常好了 |
App 上的基础组件现在是不会渲染的,也就是说下面的 View 是不会渲染到页面上的。 class App extends React.Component {
render() {
return (
<View id="app">
{this.props.children}
</View>
);
}
} |
|
||
render() { | ||
render( | ||
React.createElement(App, null, this.pages.map(p => p.element)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在这里处理一下呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我是不打算支持。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
什么原因呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没什么用,支持这个能用的地方就是做 Layout,但是现在 App 里是没法区分当前渲染的哪个页面的,也就是没办法不同的页面不同 Layout,有点鸡肋。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没事不用区分。
现在小程序自定义头部,tabBar,Modal等等,都是每个页面重复引入,对这块很有帮助
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
太复杂了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不对,这种思路还是全局组件
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该是页面挂载的时候,把共用组件带入一起渲染
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
然后要怎么通信,开发者自己决定就好了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
试了一下,确实很鸡肋。
写起来太麻烦了 |
这样的写法会让开发者感到困惑,明明是个 React 组件,但是不能真正渲染。 Taro 的 app 文件就是这么写的。 是不是可以改成在 App 里提供 |
其实不止 taro 这样,其他的框架也是类似的,App 里面是不渲染的,我觉得不用改这样就挺好 |
902e73f
to
68c3179
Compare
@Pochodaydayup 你说Taro和其他框架也有类似的处理方式,有文档或者链接可以看一下吗? |
我认为依赖 我个人对在App上创建React实例的需求持保留态度。 |
61eb9f8
to
e0ac1c7
Compare
e0ac1c7
to
185a14b
Compare
console.log('onShow', options); | ||
} | ||
|
||
return() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是 render () , 不是 return () 吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💣
背景
小程序本身是个多页应用。目前 Remax 的实现也是在每个页面上创建一个 React 实例。
问题
多页导致的问题就是数据共享,多个 React 实例间没办法通过 Context 来共享状态,这也是为什么现在没办法直接在 Remax 上用 redux 的原因(#122)。
解法
这个 PR 尝试在 App 上创建一个 React 实例,然后每个页面再通过 portal 各自渲染到自己的 container 上。
这样做的好处就是我们 App 变成了整个应用的总入口:
这也意味着我们可以以非常小的成本去接入类似 redux 这种需要一个全局 Provider 的库(#152)。页面间的状态共享完全可以用 Context 的方式来实现,更加的 React 了!