Menu

Introducing xansync – Lightweight Async Data Utilities for React
📰

Introducing xansync – Lightweight Async Data Utilities for React

DEV Community: nextjs·Naxrul Ahmed·1 day ago
#XYhBTFNo
#devtonextjs#devto#dev#xansync#error
Long article (327 words) — no AI summary yet.
Reading 0:00
15s threshold

Managing asynchronous data in React components often requires repetitive state management for loading, errors, and resolved data.

I built xansync to make this process simpler.

xansync is a lightweight React utility library that provides a simple hook and a higher-order component for handling asynchronous operations.

Why xansync?

Instead of repeatedly writing useState , useEffect , and async request logic, you can use a single hook to manage everything.

Installation

npm install xansync

Enter fullscreen mode

Exit fullscreen mode

Using useSync

import { useSync } from "xansync" ;

function Posts ( ) { const { data , isLoading , error , reload } = useSync ( async ( ) => { const response = await fetch ( "https://jsonplaceholder.typicode.com/posts" ) ;

if ( ! response . ok ) { throw new Error ( "Failed to fetch posts" ) ; }

return response . json ( ) ; } , [ ] ) ;

if ( error ) return < p > { error . message } </ p > ;

return ( < div > { isLoading && < p > Loading . . . </ p > }

{ data ? .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.