Back

typescript

  • 0
  • General
Sandipan SIngh
26 Aug, 2024, 18:27

In react to native

import { Appwrite } from 'appwrite';// appwrite import statement import appwriteConfig from './appwrite';// import statement

//Initializing Appwrite const appwrite = new Appwrite(); appwrite.setEndpoint(appwriteConfig.endpoint).setProject(appwriteConfig.project);

This code works in .jsx file but not working in .tsx

TL;DR
Developers discussing setting up user authentication with Appwrite in a React Native project. They address issues with the AppwriteConfig file, recommended setup, and importing the Appwrite library correctly. The solution provided includes ensuring the AppwriteConfig is in a .ts file, importing Appwrite properly, and specifying the file types correctly for the imports. They also check if the tsconfig is configured correctly and discuss the errors encountered.
Sandipan SIngh
26 Aug, 2024, 18:28

If i do import { Appwrite } from ‘appwrite’

It’s works in jsx file format But did not works in tsx file type

Kenny
26 Aug, 2024, 18:29

Did it give you any errors?

Kenny
26 Aug, 2024, 18:29

Do you have your tsconfig setup correctly?

Sandipan SIngh
26 Aug, 2024, 18:49

import React from 'react'; import { Appwrite } from 'appwrite'; import appwriteConfig from '../src/appwrite/AppwriteConfig'; import { View, Text, Image, StyleSheet, TouchableOpacity, Linking } from 'react-native'; import Colors from '@/constants/Colors'; import { useRouter } from 'expo-router'; import welcomeImage from '../assets/images/icon.png'; const welcome_image = Image.resolveAssetSource(welcomeImage).uri;

const appwrite = new Appwrite(); appwrite.setEndpoint(appwriteConfig.endpoint).setProject(appwriteConfig.project);

const welcomeScreen = () => { const router = useRouter(); const openPrivacyPolicy = () => { Linking.openURL('https://quickgram.in'); }; const openTermsOfService = () => { Linking.openURL('https://quickgram.in'); }; const handleAgreeAndContinue = () => { router.push(./authentication/phonenumber/VerifyPhoneScreen); };

return (

TypeScript
<View style={styles.container}>
  <Image source={{ uri: welcome_image }} style={styles.welcome} />
  <Text style={styles.headline}>Welcome to Quickgram</Text>
  <Text style={styles.description}>
    Read our{' '}
    <Text style={styles.link} onPress={openPrivacyPolicy}>
      Privacy Policy
    </Text>
    . {'Tap "Agree & Continue" to accept the '}
    <Text style={styles.link} onPress={openTermsOfService}>
      Terms of Service
    </Text>
    .
  </Text> 
    <TouchableOpacity style={styles.button}  onPress={handleAgreeAndContinue} >
    
      <Text style={styles.buttonText}>Agree & Continue</Text>
    </TouchableOpacity>

</View>

); };

const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20, backgroundColor: '#fff', }, welcome: { width: '80%', height: 280, borderRadius: 60, marginBottom: 80, }, headline: { fontSize: 24, fontWeight: 'bold', marginVertical: 20, }, description: { fontSize: 14, textAlign: 'center', marginBottom: 80, color: Colors.gray, }, link: { color: Colors.primary, }, button: { width: '100%', alignItems: 'center', }, buttonText: { color: Colors.primary, fontSize: 22, fontWeight: '500', }, });

export default welcomeScreen;

Sandipan SIngh
26 Aug, 2024, 18:49

tsconfig

{ "extends": "expo/tsconfig.base", "compilerOptions": { "strict": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "paths": { "@/": [ "./" ] } }, "include": [ "/*.ts", "/.tsx", ".expo/types/**/.ts", "expo-env.d.ts" , "app/index.tsx", "app/_layout.tsx" ] }

Sandipan SIngh
26 Aug, 2024, 18:50

AppwriteConfig.tsx

import { Client, Account, Databases, Functions, Teams } from 'appwrite';

export const API_ENDPOINT = 'https://cloud.appwrite.io/v1' export const PROJECT_ID = 'my_project_id'

const client = new Client() .setEndpoint(API_ENDPOINT) .setProject(PROJECT_ID);

export const account = new Account(client);

export default client;

Sandipan SIngh
26 Aug, 2024, 18:52
Sandipan SIngh
26 Aug, 2024, 18:52

@Kenny @Moderator can you help me

i am new to appwrite

Its_MS
26 Aug, 2024, 18:54

shouldn't appwriteconfig.tsx be

import { Client, Account, ID } from 'react-native-appwrite';

You are using react-native right?

Guille
26 Aug, 2024, 18:54

Indeed appwrite do not export Appwrite, you should do import appwrite from "appwrite"

Kenny
26 Aug, 2024, 18:54

Why is your appwrite config a tsx file, should it not be a ts file?

Its_MS
26 Aug, 2024, 18:55

should be a .ts file yeah

Sandipan SIngh
26 Aug, 2024, 18:55

yes i am using react native

Sandipan SIngh
26 Aug, 2024, 18:56

yeah i did that

Kenny
26 Aug, 2024, 18:57

Why are you doing this here

TypeScript
const appwrite = new Appwrite();
appwrite.setEndpoint(appwriteConfig.endpoint).setProject(appwriteConfig.project);

Is this not taken care of in your AppwriteConfig file?

Kenny
26 Aug, 2024, 18:58

I think you could benefit from reading the docs a bit more and following the getting started tutorial.

https://appwrite.io/docs/quick-starts/react-native

Sandipan SIngh
26 Aug, 2024, 18:59
Sandipan SIngh
26 Aug, 2024, 19:00

yeah

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more