Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/barisates/react-sync-hooks
Useful hooks you can use in asynchronous processes.
https://github.com/barisates/react-sync-hooks
Last synced: 2 days ago
JSON representation
Useful hooks you can use in asynchronous processes.
- Host: GitHub
- URL: https://github.com/barisates/react-sync-hooks
- Owner: barisates
- License: mit
- Created: 2022-11-23T11:32:51.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-24T06:17:54.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T19:28:36.515Z (16 days ago)
- Language: TypeScript
- Size: 127 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-sync-hooks
Useful hooks you can use in asynchronous processes.**Live Demo [CodeSandbox](https://codesandbox.io/s/react-sync-hook-ddbbqm "CodeSandbox")**
# usePromiseState
You can get the callback after the update is complete without using useEffect on state updates. In this way, it simplifies management in consecutively State updates.
#### Basic Usage
```javascript
import { usePromiseState } from "react-sync-hooks";export default function App() {
const [promiseState, setPromiseState] = usePromiseState(0);return (
{
setPromiseState(
1,
// Triggered when state is updated.
(s: any) => {
console.log("State Updated: " + s);
}
);
}}
>
Set Promise State: {promiseState}
);
}
```# useQueueState
It provides a synchronous update of state updates that occur asynchronously by queuing them.
#### Basic Usage
```javascript
import { useQueueState } from "react-sync-hooks";export default function App() {
const [queueState, setQueueState] = useQueueState(0);return (
{
// Queues concurrent updates
setQueueState((s: any) => s + 1);
setQueueState((s: any) => s + 1);
setQueueState((s: any) => s + 1);
}}
>
Set Queue State: {queueState}
);
}
```