From e1d8afc6e9444ec98a39814d689e2c3b4d2c36d9 Mon Sep 17 00:00:00 2001 From: amrocha Date: Thu, 12 Sep 2019 16:45:45 -0700 Subject: [PATCH] Update useEffects flow --- scripts/splash/index.tsx | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/scripts/splash/index.tsx b/scripts/splash/index.tsx index a60f38b5a8d..91b0c24a4fa 100644 --- a/scripts/splash/index.tsx +++ b/scripts/splash/index.tsx @@ -2,6 +2,7 @@ import path from 'path'; import React, {useState, useEffect} from 'react'; import {Box, Text, Color, render} from 'ink'; import sortBy from 'lodash/sortBy'; +import {argv} from 'yargs'; import {getGitStagedFiles, getDependencies} from './treebuilder'; const excludedFileNames = (fileName) => @@ -77,7 +78,8 @@ const Components = ({components, status}) => ( {status === 'loading' && ( - ⏳{' '}Please wait during compilation… Beep boop beep 🤖 + ⏳{' '} + Please wait during compilation… Beep boop beep 🤖 )} @@ -131,25 +133,25 @@ const App = () => { const getStagedFiles = async () => { const staged = (await getGitStagedFiles('src/')) as string[]; setStagedFiles(staged); - - if (staged.length === 0) { - setDataStatus('loaded'); - } }; getStagedFiles(); }, []); - useEffect(() => { - if (stagedFiles.length > 0) { - const dependencies = getDependencies( - 'src/**/*.tsx', - '*.test.tsx', - stagedFiles, - ); - setData(formatDependencies(dependencies)); + useEffect( + () => { + if (stagedFiles.length !== 0) { + const dependencies = getDependencies( + 'src/**/*.tsx', + '*.test.tsx', + stagedFiles, + ); + setData(formatDependencies(dependencies)); + } + setDataStatus('loaded'); - } - }, [setData, stagedFiles]); + }, + [setData, stagedFiles], + ); return (