Skip to content

Commit

Permalink
Update useEffects flow
Browse files Browse the repository at this point in the history
  • Loading branch information
amrocha committed Sep 12, 2019
1 parent 4a575dd commit e1d8afc
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions scripts/splash/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -77,7 +78,8 @@ const Components = ({components, status}) => (
<React.Fragment>
{status === 'loading' && (
<Box marginLeft={4} marginBottom={1}>
{' '}Please wait during compilation… Beep boop beep 🤖
{' '}
Please wait during compilation… Beep boop beep 🤖
</Box>
)}

Expand Down Expand Up @@ -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 (
<React.Fragment>
Expand Down

0 comments on commit e1d8afc

Please sign in to comment.