i have project in react-native and its ok , my problem is when i tried to import component in another component its failed but when import at index.android.js its ok why ??
index.android.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
ToastAndroid,
ListView,
Navigator,
} from 'react-native';
import LoginView from './App/LoginView';
its ok but when tried to import the same in another screen like this
import React, { Component } from 'react';
import {
StyleSheet,
ToolbarAndroid
,AppRegistry,
View,
Text,
TouchableHighlight,
TextInput,
ListView,ActionButton,
Image
} from 'react-native';
import LoginView from './App/LoginView';
export default class MyOrders extends Component
{
i got this error , "Ruquring unknown module if you are sure the module is there try to restarting the packeger or running npm install" ????
Possible cause may be relative path('./App/LoginView') could be wrong with respect to the component while importing.Try updating the relative path accordingly.After updating stop the react-native dev server and again start it using react-native start.
Let us consider that you are importing AboutUs page in index.ios.js
by using the following
var AboutUs = require('./Views/AboutUs');
AboutUs.js is located in "Views" directory which is located in place where index.ios.js page located. And in AboutUs.js page you have to export the component by
module.exports = AboutUs;
Where,
class AboutUs extends Component {
.....
}
Related
I have a "small" problem trying to use realm in combination with my react-native app.
I just started with react native and I have installed and updated everything I need for development.
I installed first realm with the command
npm install realm
after that I followed the tutorial given by MongoDB.
But all I get is this error:
Unexpected identifier 'realm'. Expected ';' after variable declaration
After that I tried to look at a template provided by #realm/react.
I installed it and started to build the aplication on my phone via react-native run-android
But I get the exact same error without changing anything.
does realm only work with a specific version of react-native?
or am I doing somthing wrong?
I am getting that error even by just declaring a scheme.
import React, { useState } from 'react';
import { View, Text, StyleSheet, TouchableOpacity,ScrollView, Image, Alert } from 'react-native';
import { NavigationContainer } from '#react-navigation/native';
import { createStackNavigator, TransitionPresets, CardStyleInterpolators } from '#react-navigation/stack';
import { Icon, Button } from "#rneui/themed";
import { styles } from './CSS/style';
import Realm from "realm";
const TaskSchema = {
name: "Task",
properties: {
_id: "int",
name: "string",
status: "string?",
},
primaryKey: "_id",
};
I want to use RecordScreen NativeModule in my react native app.
import {NativeModules} from 'react-native'
console.log(NativeModules) // This is empty {}
console.log(NativeModules.RecordScreen) // This is null
Currently I'm testing on android device yarn android build.
What is the reason for NativeModules is empty and NativeModules.RecordScreen is null ?
import {requireNativeComponent} from 'react-native';
const RecordComponent = requireNativeComponent('RecordComponent')
console.log(RecordComponent);
Try this instead
or if you wish to use the same one you can also do it like this:
import NativeModules from 'react-native'
When I am loading this LoginScreen.js I m getting the above mentioned exception.
Before that I had installed
npm install #material-ui/core
import React from 'react';
import {Button} from '#material-ui/core/Button';
import { View } from 'react-native';
export default function LoginScreen() {
return (
<View>
<Button></Button>
</View>
);
}
You need to import differently. Try as the following:
import Button from '#material-ui/core/Button';
// or
import { Button } from '#material-ui/core';
Check from the official documentation here: Button API - Import.
I hope this helps!
I am implementing the react-native-push-notification package in react-native.
In the example on the link: https://github.com/zo0r/react-native-push-notification#2-specify-handlers-for-the-notification-actions.
Error is displayed: Can't find variable: DeviceEventEmitter.
What can I do?
You need to import the DeviceEventEmitter from 'react-native'
import { DeviceEventEmitter } from 'react-native';
I am trying to integrate my react native app with smooch.io following this instructions. I have succesfully installing the module and configure MainApplication.java. Now i have problem when trying to show the conversation screen. Where should i put Smooch.show() in my react native app? Here is my index.android.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
View
} from 'react-native';
import Smooch from 'react-native-smooch';
export default class SmoochTest extends Component {
componentDidMount() {
Smooch.show();
}
render() {
return (
<View style={styles.container}>
</View>
);
}
}
const styles = StyleSheet.create({
// some style
});
AppRegistry.registerComponent('SmoochTest', () => SmoochTest);
I ran into a similar issue - did you link it? react-native link react-native-smooch. That solved it for me.