File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import React , { useEffect } from "react" ;
1+ import React from "react" ;
22
33import styles from "./App.module.css" ;
4- import useAppState from "./useAppState" ;
5- import normalizeString from "./util/normalizeString " ;
4+ import useAppState from "./hooks/ useAppState" ;
5+ import useLoadData from "./hooks/useLoadData " ;
66import pluralize from "./util/pluralize" ;
77
88function App ( ) {
99 const [ state , dispatch ] = useAppState ( ) ;
10-
11- useEffect ( ( ) => {
12- fetch ( "fruits.txt" )
13- . then ( ( response ) => response . text ( ) )
14- . then ( ( text ) => {
15- dispatch ( {
16- type : "load-data" ,
17- wordPack : text . split ( "\n" ) . map ( normalizeString ) . filter ( Boolean ) ,
18- } ) ;
19- } ) ;
20- } , [ dispatch ] ) ;
10+ useLoadData ( dispatch ) ;
2111
2212 switch ( state . phase ) {
2313 case "pre-game" : {
Original file line number Diff line number Diff line change 11import { useReducer , type Dispatch } from "react" ;
22
3- import getRandomElement from "./util/getRandomElement" ;
4- import normalizeString from "./util/normalizeString" ;
3+ import getRandomElement from ".. /util/getRandomElement" ;
4+ import normalizeString from ".. /util/normalizeString" ;
55
66export type State = Readonly <
77 | {
Original file line number Diff line number Diff line change 1+ import { type Dispatch , useEffect } from "react" ;
2+
3+ import normalizeString from "../util/normalizeString" ;
4+
5+ export default function useLoadData (
6+ dispatch : Dispatch < { type : "load-data" ; wordPack : readonly string [ ] } > ,
7+ ) {
8+ useEffect ( ( ) => {
9+ fetch ( "fruits.txt" )
10+ . then ( ( response ) => response . text ( ) )
11+ . then ( ( text ) => {
12+ dispatch ( {
13+ type : "load-data" ,
14+ wordPack : text . split ( "\n" ) . map ( normalizeString ) . filter ( Boolean ) ,
15+ } ) ;
16+ } ) ;
17+ } , [ dispatch ] ) ;
18+ }
You can’t perform that action at this time.
0 commit comments