Open DwsCode88 opened 3 years ago
@DwsCode88 Could you please explain it better? I just couldn't understand. Showing some code will also help
`import React, {useEffect, useRef, useState} from 'react'; import { View, Text, SafeAreaView, StyleSheet, FlatList, TouchableOpacity, ActivityIndicator, StatusBar, AppState, Button, Image, Linking, TextInput, Keyboard, Alert, } from 'react-native'; import CurrencyInput from 'react-native-currency-input'; import {API, graphqlOperation, Auth, Amplify} from 'aws-amplify'; import {globleStyles} from './global'; import {getCar, getUser} from '../../graphql/queries'; import {Root, Popup} from 'popup-ui'; import ReactNativeForegroundService from '@supersami/rn-foreground-service'; import RNLocation from 'react-native-location'; import Geolocation from 'react-native-geolocation-service'; import as TaskManager from 'expo-task-manager'; import as Location from 'expo-location'; import { checkBalance, createloginlink, instantpayout, transferfunds, updateCar, } from '../../graphql/mutations'; import {Logger} from 'aws-amplify'; Amplify.Logger.LOG_LEVEL = 'DEBUG'; import BackgroundTimer from 'react-native-background-timer'; import NotificationSounds, { playSampleSound, stopSampleSound, } from 'react-native-notification-sounds';
const logger = new Logger('foo', 'INFO');
const ManageMoney = ({route, navigation}) => { const appState = useRef(AppState.currentState); const [appStateVisible, setAppStateVisible] = useState(appState.current); const item = route.params; console.log('DriverDetails', item); const [car, setCar] = useState(null); const [name, setName] = useState(null); const [pendingBal, setPendingBal] = useState(null); const [availableBal, setAvailableBal] = useState(null); const [loginurl, setLoginURL] = useState(null); const [shouldShow, setShouldShow] = useState(true); const [modalVisible, setModalVisible] = useState(false); const [payoutStatus, setPayOutStatus] = useState(false);
const [number, onChangeNumber] = React.useState(null);
useEffect(() => { Auth.currentUserInfo() .then(res => { console.log(res); setName(res.attributes['custom:Name']); }) .catch(err => { console.error(err); }); }, []);
useEffect(() => { const fetchCar = async () => { try { const userData = await Auth.currentAuthenticatedUser(); const carData = await API.graphql( graphqlOperation(getCar, {id: userData.attributes.sub}), ); setCar(carData.data.getCar); console.log(carData); } catch (e) { console.error(e); } }; fetchCar(); }, [name]);
const instant = async () => { const response = await API.graphql( graphqlOperation(instantpayout, { driverPayAcct: car.driverPayAcct, driverpay: number * 100, }), ); console.log('stripe data', response); console.warn(response); setPayOutStatus(response.data.instantpayout.returninfo); console.warn('Instant', payoutStatus); if (payoutStatus) { return Alert.alert('Payout', 'Your pay out has been processed.', [ // The "Yes" button { text: 'Okay', onPress: () => { onChangeNumber({ ...null, }); CheckBalance(); }, }, // The "No" button // Does nothing but dismiss the dialog when tapped2.00 ]); } };
useEffect(() => { CheckBalance(); }, [car]);
const CheckBalance = async () => { const response = await API.graphql( graphqlOperation(checkBalance, { driverPayAcct: car.driverPayAcct, }), ); console.log('stripe data', response); setAvailableBal(response.data.CheckBalance.availableBal); setPendingBal(response.data.CheckBalance.pendingBal); };
const LoginLink = async () => { const response = await API.graphql( graphqlOperation(createloginlink, { driverPayAcct: car.driverPayAcct, }), ); console.log('stripe data', response); setLoginURL(response.data.createloginlink.url); };
useEffect(() => { LoginLink(); }, [car]);
console.log('LoginLink', loginurl);
const Bal = Max amount you can transfer out $${availableBal / 100}
;
console.log(number);
return (
); };
const styles = StyleSheet.create({ container: { flex: 1, padding: 7, marginTop: StatusBar.currentHeight, }, TextStyle: { color: '#E91E63', textDecorationLine: 'underline', }, input: { height: 40, margin: 12, borderWidth: 1, padding: 10, }, inputContainer: { paddingTop: 15, }, textInput: { borderColor: '#CCCCCC', borderTopWidth: 1, borderBottomWidth: 1, height: 50, fontSize: 25, paddingLeft: 20, paddingRight: 20, }, saveButton: { borderWidth: 1, borderColor: '#007BFF', backgroundColor: '#007BFF', padding: 15, margin: 5, }, saveButtonText: { color: '#FFFFFF', fontSize: 20, textAlign: 'center', }, });
export default ManageMoney; `
When I reset the state it shows $NaN Instead of placeholder like on first load
@DwsCode88 if you want help you need to make us understand the problem, this code you shared is illegible an unreproducible (we can't run it)
So i have a default placeholder im using and then i set state back to null instead of showing the placeholder it shoes $NaN