Skip to content

Commit 36a69ad

Browse files
author
babin
committed
main 🧊 update readme for core
1 parent 4667d81 commit 36a69ad

File tree

5 files changed

+93
-26
lines changed

5 files changed

+93
-26
lines changed

‎packages/core/README.md

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,71 @@
1-
# 🚀 reactuse core
1+
<div align="center">
2+
<a href="https://reactuse.dev">
3+
<picture>
4+
<img alt="React Use logo" src="https://siberiacancode.github.io/reactuse/logo.svg" height="128">
5+
</picture>
6+
</a>
7+
<h1>React Use</h1>
28

3-
the largest and most useful hook library
9+
<a href="https://www.npmjs.com/package/@siberiacancode/reactuse"><img alt="NPM version" src="https://img.shields.io/npm/v/@reactuses/core.svg?style=for-the-badge&labelColor=000000"></a>
10+
<a href="https://github.com/siberiacancode/reactuse/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@reactuses/core.svg?style=for-the-badge&labelColor=000000"></a>
11+
<a href="https://github.com/siberiacancode/reactuse/discussions"><img alt="Join the community on GitHub" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&logo=React&labelColor=000000&logoWidth=20"></a>
412

5-
## 🦉 Philosophy
13+
</div>
614

7-
**🚀 React Use** this is a library that will allow you to easy and simple to use React hooks. Unlike its competitors, this package takes into account the features of React and also contains a huge number of useful hooks.
15+
React Use delivers **production-ready hooks** that solve real-world problems. Built with **TypeScript-first** approach, **SSR compatibility**, and **tree-shaking optimization** - everything you need to build modern React applications. Improve your react applications with our library 📦 designed for comfort and speed.
816

9-
## Features
17+
## Documentation
1018

11-
- **TypeScript support out of the box** - full typed package
12-
- **SSR** - package work with server side render
19+
Visit https://siberiacancode.github.io/reactuse to view the full documentation.
20+
21+
## Getting Started
22+
23+
```bash
24+
npm install @siberiacancode/reactuse
25+
```
26+
27+
```tsx
28+
import { useCounter } from '@reactuses/core';
29+
30+
function App() {
31+
const counter = useCounter(0);
32+
33+
return (
34+
<div>
35+
<h1>Count: {const.value}</h1>
36+
<button onClick={() => const.inc()}>+1</button>
37+
<button onClick={() => const.dec()}>-1</button>
38+
</div>
39+
);
40+
}
41+
```
42+
43+
## CLI installation
44+
45+
Use the CLI to add hooks to your project with [useverse](https://www.npmjs.com/package/useverse).
46+
47+
```bash
48+
npx useverse@latest init
49+
```
50+
51+
```bash
52+
npx useverse@latest add [hook]
53+
```
54+
55+
You will be presented with a list of hooks to choose from:
56+
57+
```bash
58+
Which hooks would you like to add? › Space to select. A to toggle all.
59+
Enter to submit.
60+
61+
â—¯ useActiveElement
62+
â—¯ useAsync
63+
â—¯ useBattery
64+
â—¯ useBluetooth
65+
â—¯ useBoolean
66+
â—¯ useBreakpoints
67+
â—¯ useBrowserLanguage
68+
â—¯ useClickOutside
69+
â—¯ useClipboard
70+
â—¯ useConst
71+
```

‎packages/core/src/bundle/hooks/useAsync/useAsync.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { useEffect, useState } from 'react';
44
* @description - Hook that provides the state of an async callback
55
* @category Utilities
66
*
7-
* @param {() => Promise<Data>} callback - The async callback
8-
* @param {DependencyList} deps - The dependencies of the callback
9-
* @returns {UseAsyncReturn<Data>} - The state of the async callback
7+
* @param {() => Promise<Data>} callback The async callback
8+
* @param {DependencyList} deps The dependencies of the callback
9+
* @returns {UseAsyncReturn<Data>} The state of the async callback
1010
*
1111
* @example
1212
* const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);

‎packages/core/src/bundle/hooks/useDropZone/useDropZone.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ import { useRefState } from '../useRefState/useRefState';
1515
* @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function
1616
* @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function
1717
* @param {(event: DragEvent) => void} [options.onOver] The on over callback function
18-
* @returns {[boolean, File[] | null]} The object with drop zone states
18+
* @returns {UseDropZoneReturn} The object with drop zone states
1919
*
2020
* @example
2121
* const { overed, files } = useDropZone(ref, options);
2222
*
2323
* @overload
2424
* @param {Target} target The target element drop zone's
2525
* @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop
26-
* @returns {[boolean, File[] | null]} The object with drop zone states
26+
* @returns {UseDropZoneReturn} The object with drop zone states
2727
*
2828
* @example
2929
* const { overed, files } = useDropZone(ref, () => console.log('callback'));
@@ -35,14 +35,14 @@ import { useRefState } from '../useRefState/useRefState';
3535
* @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function
3636
* @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function
3737
* @param {(event: DragEvent) => void} [options.onOver] The on over callback function
38-
* @returns {[StateRef<Target>, boolean, File[] | null]} The object with drop zone states and ref
38+
* @returns {UseDropZoneReturn & { ref: StateRef<Target> }} The object with drop zone states and ref
3939
*
4040
* @example
4141
* const { ref, overed, files } = useDropZone(options);
4242
*
4343
* @overload
4444
* @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop
45-
* @returns {[StateRef<Target>, boolean, File[] | null]} The object with drop zone states and ref
45+
* @returns {UseDropZoneReturn & { ref: StateRef<Target> }} The object with drop zone states and ref
4646
*
4747
* @example
4848
* const { ref, overed, files } = useDropZone(() => console.log('callback'));

‎packages/core/src/bundle/hooks/useShare/useShare.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* @description - Hook that utilizes the share api
44
* @category Browser
55
*
6+
* @browserapi share https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share
7+
*
68
* @param {UseShareParams} [params] The use share options
79
* @returns {UseShareReturn}
810
*

‎packages/core/src/bundle/hooks/useStorage/useStorage.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,27 @@ const getStorageItem = (storage, key) => {
3838
* @example
3939
* const { value, set, remove } = useStorage('key', 'value');
4040
*/
41-
export const useStorage = (key, params) => {
41+
export const useStorage = (...params) => {
42+
const key = params[0];
43+
const secondParam = params[1];
4244
const options =
43-
typeof params === 'object' &&
44-
params &&
45-
('serializer' in params ||
46-
'deserializer' in params ||
47-
'initialValue' in params ||
48-
'storage' in params)
49-
? params
45+
typeof secondParam === 'object' &&
46+
secondParam &&
47+
('serializer' in secondParam ||
48+
'deserializer' in secondParam ||
49+
'initialValue' in secondParam ||
50+
'storage' in secondParam)
51+
? secondParam
5052
: undefined;
51-
const initialValue = options ? options?.initialValue : params;
52-
if (typeof window === 'undefined')
53+
const initialValue = options ? options?.initialValue : secondParam;
54+
if (typeof window === 'undefined') {
55+
const value = typeof initialValue === 'function' ? initialValue() : initialValue;
5356
return {
54-
value: typeof initialValue === 'function' ? initialValue() : initialValue
57+
value,
58+
set: () => {},
59+
remove: () => {}
5560
};
61+
}
5662
const serializer = (value) => {
5763
if (options?.serializer) return options.serializer(value);
5864
if (typeof value === 'string') return value;
@@ -88,7 +94,7 @@ export const useStorage = (key, params) => {
8894
return () => window.removeEventListener(STORAGE_EVENT, onChange);
8995
}, [key]);
9096
return {
91-
value,
97+
value: value,
9298
set,
9399
remove
94100
};

0 commit comments

Comments
 (0)