rpimc/src/screens/SettingsScreen.js
2021-11-28 19:44:00 -06:00

47 lines
No EOL
1.1 KiB
JavaScript
Executable file

import React, { useState, useEffect } from 'react';
import {
View,
Text,
TextInput,
} from 'react-native';
import {
Header,
Button,
} from 'react-native-elements';
import { useAsyncStorage } from '@react-native-async-storage/async-storage';
// I know all the previous stuff uses componets and classes, but for now this is the
// Only way I can get this to work properly
export default function App() {
const [value, setValue] = useState('value');
const { getItem, setItem } = useAsyncStorage('@storage_key');
const readItemFromStorage = async () => {
const item = await getItem();
setValue(item);
};
const writeItemToStorage = async newValue => {
await setItem(newValue);
setValue(newValue);
};
useEffect(() => {
readItemFromStorage();
}, []);
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center'}}>
<Text>Server IP: {value}</Text>
<Text>{"\n"}</Text>
<TextInput onChangeText={newValue => writeItemToStorage(newValue) } style={{borderWidth: 1, width: 100}}>{value}</TextInput>
</View>
);
}