Skip to content

Commit 9382fa9

Browse files
anton-karlovskiyaddyosmani
authored andcommitted
[docs] Bugfix/clean up (#24)
* cleaned up README * updated README for returning values for each hook or utility * updated deployed URL in README for cna-memory-considerate-animation * [docs] Minor formatting improvements
1 parent 20a4b9d commit 9382fa9

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { useNetworkStatus } from 'react-adaptive-hooks/network';
2828
import { useSaveData } from 'react-adaptive-hooks/save-data';
2929
import { useHardwareConcurrency } from 'react-adaptive-hooks/hardware-concurrency';
3030
import { useMemoryStatus } from 'react-adaptive-hooks/memory';
31-
3231
```
3332

3433
and then use them in your components. Examples for each hook and utility can be found below:
@@ -68,6 +67,8 @@ const MyComponent = () => {
6867
};
6968
```
7069

70+
`effectiveConnectionType` values can be `slow-2g`, `2g`, `3g`, or `4g`.
71+
7172
This hook accepts an optional `initialEffectiveConnectionType` string argument, which can be used to provide a `effectiveConnectionType` state value when the user's browser does not support the relevant [NetworkInformation API](https://wicg.github.io/netinfo/). Passing an initial value can also prove useful for server-side rendering, where the developer can pass an [ECT Client Hint](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/client-hints#ect) to detect the effective network connection type.
7273

7374
```js
@@ -95,6 +96,8 @@ const MyComponent = () => {
9596
};
9697
```
9798

99+
`saveData` values can be `true` or `false`.
100+
98101
This hook accepts an optional `initialSaveDataStatus` boolean argument, which can be used to provide a `saveData` state value when the user's browser does not support the relevant [NetworkInformation API](https://wicg.github.io/netinfo/). Passing an initial value can also prove useful for server-side rendering, where the developer can pass a server [Save-Data Client Hint](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/client-hints#save-data) that has been converted to a boolean to detect the user's data saving preference.
99102

100103
```js
@@ -122,6 +125,8 @@ const MyComponent = () => {
122125
};
123126
```
124127

128+
`numberOfLogicalProcessors` values can be the number of logical processors available to run threads on the user's device.
129+
125130
### Memory
126131

127132
`useMemoryStatus` utility for adapting based on the user's device memory (RAM)
@@ -141,6 +146,8 @@ const MyComponent = () => {
141146
};
142147
```
143148

149+
`deviceMemory` values can be the approximate amount of device memory in gigabytes.
150+
144151
This hook accepts an optional `initialMemoryStatus` object argument, which can be used to provide a `deviceMemory` state value when the user's browser does not support the relevant [DeviceMemory API](https://github.com/w3c/device-memory). Passing an initial value can also prove useful for server-side rendering, where the developer can pass a server [Device-Memory Client Hint](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/client-hints#save-data) to detect the memory capacity of the user's device.
145152

146153
```js
@@ -163,7 +170,7 @@ import { useNetworkStatus } from 'react-adaptive-hooks/network';
163170
const Full = lazy(() => import(/* webpackChunkName: "full" */ './Full.js'));
164171
const Light = lazy(() => import(/* webpackChunkName: "light" */ './Light.js'));
165172

166-
function MyComponent() {
173+
const MyComponent = () => {
167174
const { effectiveConnectionType } = useNetworkStatus();
168175
return (
169176
<div>
@@ -172,7 +179,7 @@ function MyComponent() {
172179
</Suspense>
173180
</div>
174181
);
175-
}
182+
};
176183

177184
export default MyComponent;
178185
```
@@ -182,7 +189,7 @@ Light.js:
182189
import React from 'react';
183190

184191
const Light = ({ imageUrl, ...rest }) => (
185-
<img src={imageUrl} alt='product' {...rest} />
192+
<img src={imageUrl} {...rest} />
186193
);
187194

188195
export default Light;
@@ -212,31 +219,29 @@ const Component = React.lazy(() => {
212219

213220
let module;
214221
switch (effectiveType) {
215-
case "3g":
216-
module = import(/* webpackChunkName: "light" */ "./Light.js");
222+
case '3g':
223+
module = import(/* webpackChunkName: "light" */ './Light.js');
217224
break;
218-
case "4g":
219-
module = import(/* webpackChunkName: "full" */ "./Full.js");
225+
case '4g':
226+
module = import(/* webpackChunkName: "full" */ './Full.js');
220227
break;
221228
default:
222-
module = import(/* webpackChunkName: "full" */ "./Full.js");
229+
module = import(/* webpackChunkName: "full" */ './Full.js');
223230
break;
224231
}
225232

226233
return module;
227234
});
228235

229-
function App() {
236+
const App = () => {
230237
return (
231-
<div className="App">
232-
<header className="App-header">
233-
<Suspense fallback={<div>Loading...</div>}>
234-
<Component />
235-
</Suspense>
236-
</header>
238+
<div className='App'>
239+
<Suspense fallback={<div>Loading...</div>}>
240+
<Component />
241+
</Suspense>
237242
</div>
238243
);
239-
}
244+
};
240245

241246
export default App;
242247
```
@@ -280,7 +285,7 @@ export default App;
280285

281286
* [Memory considerate loading](https://github.com/GoogleChromeLabs/adaptive-loading/tree/master/cra-memory-considerate-loading) with create-react-app ([Live](https://adaptive-loading.web.app/cra-memory-considerate-loading/))
282287
* [Memory considerate loading (SketchFab version)](https://github.com/GoogleChromeLabs/adaptive-loading/tree/master/cra-memory-considerate-loading-sketchfab) with create-react-app ([Live](https://adaptive-loading.web.app/cra-memory-considerate-loading-sketchfab/))
283-
* [Memory-considerate animation-toggling](https://github.com/GoogleChromeLabs/adaptive-loading/tree/master/cna-memory-considerate-animation) with create-next-app ([Live](https://cna-memory-animation.firebaseapp.com/))
288+
* [Memory-considerate animation-toggling](https://github.com/GoogleChromeLabs/adaptive-loading/tree/master/cna-memory-considerate-animation) with create-next-app ([Live](https://adaptive-loading.web.app/cna-memory-considerate-animation/))
284289

285290
* [React Dixie Mesh - memory considerate loading](https://github.com/GoogleChromeLabs/adaptive-loading/tree/master/react-dixie-memory-considerate-loading) ([Live](https://adaptive-loading.web.app/react-dixie-memory-considerate-loading/))
286291

0 commit comments

Comments
 (0)