-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added hooks readme with usage codesnippets
- Loading branch information
1 parent
0e374fd
commit e861b64
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Usage | ||
|
||
## Network | ||
React hook for getting network status (effective connection type) | ||
|
||
``` | ||
import { useEffectiveConnectionType } from './network'; | ||
const MyComponent = () => { | ||
const effectiveConnectionType = useEffectiveConnectionType(); | ||
let media; | ||
switch(effectiveConnectionType) { | ||
case 'slow-2g': | ||
media = <img className="responsive" src="…" alt="low resolution" />; | ||
break; | ||
case '2g': | ||
media = <img className="responsive" src="…" alt="medium resolution" />; | ||
break; | ||
case '3g': | ||
media = <img className="responsive" src="…" alt="high resolution" />; | ||
break; | ||
case '4g': | ||
media = <video className="responsive" src="…" controls />; | ||
break; | ||
default: | ||
media = <video className="responsive" src="…" controls />; | ||
break; | ||
} | ||
return <div>{media}</div>; | ||
}; | ||
``` | ||
|
||
## Memory | ||
React hook for getting memory status of the device | ||
|
||
``` | ||
import { useMemoryStatus } from './memory'; | ||
const MyComponent = () => { | ||
const { overLoad } = useMemoryStatus(); | ||
return ( | ||
<div> | ||
{ overLoad ? <img src='...' /> : <video src='...' /> } | ||
</div> | ||
); | ||
}; | ||
``` | ||
|
||
## Device-class | ||
React hook for getting device-class whether it's light or heavy | ||
|
||
``` | ||
import { useDeviceClass } from './device-class'; | ||
const MyComponent = () => { | ||
const deviceClass = useDeviceClass(); | ||
return ( | ||
<div> | ||
{ deviceClass === ‘light’ ? <img src='...' /> : <video src='...' /> } | ||
</div> | ||
); | ||
}; | ||
``` | ||
|
||
## Battery | ||
React hook for getting battery status | ||
|
||
``` | ||
import { useBatteryStatus } from './battery'; | ||
const MyComponent = () => { | ||
const batteryStatus = useBatteryStatus(); | ||
return ( | ||
<div> | ||
{ batteryStatus.level > 0.75 ? <video src='...' /> : <img src='...' /> } | ||
</div> | ||
); | ||
}; | ||
``` |