reactjs - 不变违规:“无标题”尚未注册。在以下情况下可能会发生这种情况: * Metro(本地开发服务器)从错误的文件夹运行
问题描述
我正计划构建一个扫描仪应用程序。我想测试来自https://www.npmjs.com/package/react-native-qrcode-scanner的给定示例,然后将其集成到我的项目中。基本上我正在尝试测试 2 个应用程序。为了实现这一点,我遇到了这个错误。它说的奇怪的是我的应用程序被命名为“无标题”,但我在 test.json 中将其命名为“测试”。
index.js:
/**
* @format
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import * as Test from './Test';
import {name as TestName} from './test.json';
AppRegistry.registerComponent(TestName, () => Test);
/*AppRegistry.registerComponent(appName, () => App);*/
测试.js:
'use strict';
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
TouchableOpacity,
Linking
} from 'react-native';
import QRCodeScanner from 'react-native-qrcode-scanner';
import { RNCamera } from 'react-native-camera';
import App from "./App";
class ScanScreen extends Component {
onSuccess = e => {
Linking.openURL(e.data).catch(err =>
console.error('An error occured', err)
);
};
render() {
return (
<QRCodeScanner
onRead={this.onSuccess}
flashMode={RNCamera.Constants.FlashMode.torch}
topContent={
<Text style={styles.centerText}>
Go to{' '}
<Text style={styles.textBold}>wikipedia.org/wiki/QR_code</Text> on
your computer and scan the QR code.
</Text>
}
bottomContent={
<TouchableOpacity style={styles.buttonTouchable}>
<Text style={styles.buttonText}>OK. Got it!</Text>
</TouchableOpacity>
}
/>
);
}
}
const styles = StyleSheet.create({
centerText: {
flex: 1,
fontSize: 18,
padding: 32,
color: '#777'
},
textBold: {
fontWeight: '500',
color: '#000'
},
buttonText: {
fontSize: 21,
color: 'rgb(0,122,255)'
},
buttonTouchable: {
padding: 16
}
});
AppRegistry.registerComponent('default', () => ScanScreen);
测试.json
{
"name": "Test",
"displayName": "Test"
}
应用程序.json
{
"name": "untitled",
"displayName": "untitled"
}
解决方案
推荐阅读
- android - Firebase 使用 Android 完成后更新 UI
- java - 如何将字符串转换为整数并将其添加到arrayList
- ruby-on-rails - 如何在 ruby on rails 中添加速率限制器?
- javascript - 只有在 GCP nginx 服务器上部署时,React 嵌套路由才起作用
- networkx - selfloop_edges() 的 AttributeError
- r - 无法在 r shiny docker 中安装 devtools
- python - 为什么 pandas.DataFrame.from_dict 不支持 pandas.DataFrame.to_dict 的所有方向?
- c# - 从 Blazor 中的自定义字符串标记插入
- r - 应用 as.numeric 后,矩阵列仍在“字符”类中
- mysql - 在 pythonanywhere 上部署 Django 项目:运行 WSGI 应用程序时出错