Skip to content

Commit

Permalink
[#35] Replace all use React directly in SettingsForm
Browse files Browse the repository at this point in the history
  • Loading branch information
ifirmawan committed Jul 5, 2023
1 parent b8c8f5b commit f8268ce
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions app/src/pages/Settings/Form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState, useMemo, useEffect } from 'react';
import { View } from 'react-native';
import { ListItem, Switch } from '@rneui/themed';
import * as Crypto from 'expo-crypto';
Expand All @@ -11,9 +11,9 @@ import DialogForm from './DialogForm';
const db = conn.init;

const SettingsForm = ({ route }) => {
const [edit, setEdit] = React.useState(null);
const [list, setList] = React.useState([]);
const [showDialog, setShowDialog] = React.useState(false);
const [edit, setEdit] = useState(null);
const [list, setList] = useState([]);
const [showDialog, setShowDialog] = useState(false);

const { serverURL, appVersion } = BuildParamsState.useState((s) => s);
const { username, password, authenticationCode, useAuthenticationCode } = AuthState.useState(
Expand All @@ -27,7 +27,7 @@ const SettingsForm = ({ route }) => {
UIState,
UserState,
};
const [settingsState, setSettingsState] = React.useState({
const [settingsState, setSettingsState] = useState({
serverURL,
username,
password,
Expand All @@ -40,7 +40,7 @@ const SettingsForm = ({ route }) => {
syncWifiOnly,
});

const editState = React.useMemo(() => {
const editState = useMemo(() => {
if (edit && edit?.key) {
const [stateName, stateKey] = edit?.key?.split('.');
return [store[stateName], stateKey];
Expand Down Expand Up @@ -136,17 +136,17 @@ const SettingsForm = ({ route }) => {
conn.tx(db, insertQuery, []);
};

const settingsID = React.useMemo(() => {
const settingsID = useMemo(() => {
return route?.params?.id;
}, [route]);

React.useEffect(() => {
useEffect(() => {
const findConfig = config.find((c) => c?.id === settingsID);
const fields = findConfig ? findConfig.fields : [];
setList(fields);
}, [settingsID]);

React.useEffect(() => {
useEffect(() => {
const selectQuery = query.read('config', { id: 1 });
conn.tx(db, selectQuery, [1]).then(({ rows }) => {
if (rows.length) {
Expand Down

0 comments on commit f8268ce

Please sign in to comment.