Exhaustive hooks (#300)

This commit is contained in:
Jaco Greeff
2020-03-27 08:52:52 +01:00
committed by GitHub
parent 3edeae30a0
commit 95882ea875
11 changed files with 890 additions and 456 deletions
+8 -7
View File
@@ -47,7 +47,7 @@ const styles = StyleSheet.create({
const globalAny = global as unknown as Window;
export default function App (): React.ReactElement<{}> | null {
const [ready, setReady] = useState(false);
const [isReady, setReady] = useState(false);
const [address, setAddress] = useState<string | null>(null);
const [phrase, setPhrase] = useState<string | null>(null);
const [ss58Format, setSS58Format] = useState(42);
@@ -65,12 +65,13 @@ export default function App (): React.ReactElement<{}> | null {
};
useEffect((): void => {
ready && _onClickNew();
}, []);
isReady && _onClickNew();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isReady]);
useEffect((): void => {
ready && address && setAddress(keyring.encodeAddress(address, ss58Format));
}, [address, ss58Format]);
isReady && address && setAddress(keyring.encodeAddress(address, ss58Format));
}, [address, isReady, ss58Format]);
const initialize = async (): Promise<void> => {
try {
@@ -84,11 +85,11 @@ export default function App (): React.ReactElement<{}> | null {
_onClickNew();
};
if (!ready) {
if (!isReady) {
initialize();
}
if (!ready || !address || !phrase) {
if (!isReady || !address || !phrase) {
return null;
}
+3 -3
View File
@@ -40,9 +40,9 @@
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@polkadot/keyring": "^2.6.2",
"@polkadot/util": "^2.6.2",
"@polkadot/util-crypto": "^2.6.2",
"@polkadot/keyring": "^2.7.0-beta.8",
"@polkadot/util": "^2.7.0-beta.8",
"@polkadot/util-crypto": "^2.7.0-beta.8",
"@react-native-community/cli-platform-ios": "^4.3.0",
"@types/react-test-renderer": "16.9.2",
"babel-jest": "^25.1.0",