gpt4 book ai didi

reactjs - 在 React 和 React-Native 之间共享组件/逻辑

转载 作者:行者123 更新时间:2023-12-01 22:24:45 25 4
gpt4 key购买 nike

我正在尝试创建一个针对网络和移动设备的应用程序。这个想法是创建渲染方式不同但共享逻辑的 React 组件。

React v.014 博客文章指出“我们将主要的 React 包分成两部分:react 和 React-dom。这为编写可在 Web 版本的 React 和 React Native 之间共享的组件铺平了道路。React 包包含 React.createElement、.createClass、.Component、.PropTypes、.Children 以及与元素和组件类相关的其他帮助程序。我们将它们视为构建组件所需的同构或通用助手。”

我找到了一个很好的例子( http://blog.benoitvallon.com/projects/a-mobile-desktop-and-website-app-with-the-same-code/ ),它使用相同的概念并完成了结果(react-native 0.13.6 和 React 0.14.2)。

在这段代码中,你不会看到什么特别的,只是一个关于如何扩展 React-Native 命名约定系统以包含 Web 版本的聪明想法。当我升级到最新的react-native时,它会提示任何使用react包中的React.Component而不是react-native的组件。

这很令人困惑,因为 0.14 版本似乎表明这正是移动固件的点。让React创建组件,让react-dom处理DOM,让react-native处理ios/android View 。

我认为这是一个绝妙的主意,但我似乎无法解决这个特定的问题。任何想法、想法将不胜感激。

谢谢

最佳答案

以这种方式使 React Native 工作的转变正在进行中,但尚未完成。请参阅AMA .

We are working hard to stop using our fork such that people can use require('react') and work the same as require('react-native'), this will make it possible for all the third party plugins to work on both places without doing anything.

Right now we can't use relay on the open source version of react-native without forking it, which is a huge shame and we're working on fixing that.

关于reactjs - 在 React 和 React-Native 之间共享组件/逻辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34318308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com