共享反应本地组件
我是React,React-Nodejs的新手。
我尝试通过 npm init 创建节点模块。在此模块中,我创建了一个组件 - 用于启动样式按钮。我通过 npm pack poffage.json 文件中的一个链接通过“ file:../ shared/_dist/sharde-1.0.tgz)包装了此链接。 “依赖项部分。
在我的共享index.js中,
import MyButtonFirst from './components/buttons/MyButtonFirst';
module.exports = { MyButtonFirst };
在React应用程序中是
import React from 'react;
import { MyButtonFirst } from 'shared';
export default function MySharedButton()
{
return <MyButtonFirst />;
}
它有效!
,然后我尝试创建使用 react-native-native-andAsync-staregora/async-streetage的组件/strong>(通过共享项目中的NPM安装)。在增加版本后,npm pack,链接和安装新版本的软件包我会发现 asyncstorage在Android运行后 null 。
为什么异步是无效的?我在两个项目中都创造了依赖吗? (这是一个奇怪的解决方案 - 尽管有效,但对我来说并不适合) 如何共享例如图标,图像等的资源
等代码我们需要共享 - 图标,上下文(用户,主题等),错误处理,API调用等...我们不希望将其作为一个大权利控制应用程序开发,但是作为单个个人的几个小应用程序角色。
如何在更反应的应用程序之间共享代码的最佳方法是什么?
I am newbie in react, react-native and nodejs.
I tried create node module via npm init. In this module i created a component - for start styled button. I packed this via npm pack a link in application in package.json file by "file:../shared/_dist/shared-1.0.0.tgz" in dependency section.
in my shared index.js is
import MyButtonFirst from './components/buttons/MyButtonFirst';
module.exports = { MyButtonFirst };
in react application is
import React from 'react;
import { MyButtonFirst } from 'shared';
export default function MySharedButton()
{
return <MyButtonFirst />;
}
It works!
Then i tried create component which using react-native-async-storage/async-storage (via npm install in shared project). After increase version, npm pack, link and install new version of package I get error that AsyncStorage is null after android run.
Why AsyncStorage is null? Have I create dependecy in both projects? (that's a weird solution - it doesn't feel right to me, although it works)
How to share for example resources like icons, images etc.
We need to develop three applications on the same data (API) in the field of sports for different types of users (athlete, referee, administrator of the sports ground) and a lot of code we need to share - icons, contexts (user, theme etc...), error handling, API calls etc... We don't want develop it as one big rights-controlled application, but as several small applications for individual roles.
What is the best way how to share code between more react-native apps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
andncstorage
已弃用,请参见在这里。您可以根据数据库的反馈(用户的角色)链接到不同应用程序的start.js。
否则,它将以例如登录和注册儿童组件(例如登录和注册)路线路由受欢迎的组件。
像这样,您可以将应用程序的标准文件夹保持在react中,并在它们之间的公共文件夹中共享所有童装,挂钩和文件:
要使用户分开,您将用户的角色存储在cookie中,并在服务器端检查该角色。
如果cookie为空,它将始终带回欢迎组件。
旁注:当然,文件夹结构始终取决于Bundler设置!因此,您的应用程序的文件夹结构可能与图像上的文件夹可能不同。
AsyncStorage
is deprecated, see here.You could create a start.js that links to different apps based on the feedback of your database (the roles of your users).
Else, it will route to a welcome component with, for example, a login and registration child-component.
Like that, you can keep the standard folder tree of an application in React and share all child-components, hooks and files in the public folder between them:
To keep the users separate, you store the role of the user in a cookie and check for the role on the server side.
If the cookie is empty, it will always lead back to the welcome component.
Side note: of course, the folder structure is always dependent on the bundler setup! So the folder structure of your app could differ from the one on the image.