Demo

Have you ever needed to periodically fetch data from a remote API in your React Native app? Maybe you're building a chat client that polls for new messages, or a dashboard that refreshes frequently with updated metrics?

Most developers reach for this kind of code:

useEffect(() => {
  const interval = setInterval(async () => {
    const response = await fetch("https://your-api.com/status");
    const data = await response.json();
    // do something
  }, 1000);

  return () => clearInterval(interval);
}, []);

This works... until it doesn’t:

  • Multiple polling tasks run in parallel and get messy ☠️
  • You start hitting performance issues and blocking the JS thread 🚨
  • Managing lifecycles and cleanup becomes tedious 🧠
  • You process the same data repeatedly, wasting CPU cycles 📉

That’s why I built react-native-sync-tasks — a blazing-fast, native JSI-based polling library for React Native, written in C++ and Rust, with a clean and intuitive JS API. It runs outside of the JS thread, leveraging native threads for maximum performance.


🧠 Why use SyncTasksManager?

✅ Executes periodic polling in native threads, not in JS timers
✅ Callback only fires when the response has changed (using response hash)
✅ Centralized task management with start/stop control
✅ Keeps your JS thread free and UI smooth
✅ Zero runtime dependencies — fully native via JSI


✨ Features

  • 🔁 Periodic HTTP polling with configurable interval
  • 📡 onData callback when data is received (only if changed)
  • onError callback for failed requests
  • 🧵 Native execution via C++/Rust threads (JSI)
  • 🧠 Smart deduplication (response body hash)
  • ✅ Centralized control over all polling tasks

🚀 Quick Example

import { createTask, SyncTasksManager } from 'react-native-sync-tasks';

const task = createTask({
  config: {
    url: 'https://jsonplaceholder.typicode.com/posts/1',
    interval: 2000,
  },
  onData: (data) => console.log('DATA:', data),
  onError: (err) => console.error('ERROR:', err),
});

SyncTasksManager.addTask(task);
SyncTasksManager.startAll();

📦 Installation

npm install react-native-sync-tasks

Don’t forget to run pod install on iOS.


⚙️ Under the Hood

This library is built entirely with native performance in mind:

  • 🦀 Rust handles the HTTP logic and hashing
  • ⚙️ C++ bridges with JSI in React Native
  • 🚫 No timers or polling in JS — it’s all native

⚠️ Not a true background task

This library does not continue polling when the app is in background or terminated. It is meant for offloading polling work to native threads while the app is active.


🔍 Use cases

  • 🔄 Real-time metrics dashboards
  • 💬 Chat apps polling for new messages
  • 📲 Device status updates
  • 🔔 Periodic checks to backend APIs

🔗 Links


If you’re building something that needs smooth, high-frequency API polling without hurting performance — give it a try!

Feedback and contributions are welcome 🙌