File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed
apps/condo/domains/common/hooks Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,24 @@ const {
66 publicRuntimeConfig : { serverUrl } ,
77} = getConfig ( )
88
9- const REQUEST_KEY = '/api/version'
10- const API_ROUTE = `${ serverUrl } ${ REQUEST_KEY } `
9+ const REQUEST_CACHE_KEY = '/api/version'
10+ const FETCH_ROUTE = `${ serverUrl } /api/version `
1111
1212async function fetchBuildInfo ( ) {
13- const response = await fetch ( API_ROUTE )
13+ const response = await fetch ( FETCH_ROUTE )
1414 return await response . json ( )
1515}
1616
17+ /**
18+ * Fetch data about current build from a remote url using useSWR under the hood
19+ * Which is similar to useQuery from "apollo-client"
20+ * It has cache-validating mechanism:
21+ * 1. Return value from cache by specified key
22+ * 2. Fetch data from remote url and compare with cache value
23+ * 3. Update return value if needed
24+ */
1725export function useCurrentBuild ( ) : string {
18- const { data } = useSWR ( REQUEST_KEY , fetchBuildInfo )
26+ const { data } = useSWR ( REQUEST_CACHE_KEY , fetchBuildInfo )
1927
2028 return get ( data , 'build' , null )
2129}
Original file line number Diff line number Diff line change @@ -6,8 +6,10 @@ import { Button } from '@condo/domains/common/components/Button'
66import { useCurrentBuild } from './useCurrentBuild'
77import { usePrevious } from './usePrevious'
88
9-
10-
9+ /**
10+ * Periodically fetch information about build and compare it with previous value
11+ * If a change is found, a notification is shown to the user asking them to reload the tab
12+ */
1113export function useHotCodeReload ( ) : void {
1214 const intl = useIntl ( )
1315 const NotificationTitle = intl . formatMessage ( { id : 'HotCodeReload.title' } )
Original file line number Diff line number Diff line change 11import { useEffect , useRef } from 'react'
22
33/**
4- * Monitoring some variable value
5- * After it's change useEffect will update ref
6- * But before that will be returned previous value
4+ * Monitor some `variable` value
5+ * Until `variable` is changed its previous value would be returned
6+ * Changing the value of a variable will trigger an async ref change via useEffect
7+ * At this point, the return value will still be the same
8+ * This will catch the update state where value !== return value
9+ * After useEffect has finished, the input and output value will be the same again
710 * @param value to monitor
811 */
912export function usePrevious < T > ( value : T ) : T {
You can’t perform that action at this time.
0 commit comments