Next.js Discord

Discord Forum

Creating a singleton service to manage requests to chrome extension

Unanswered
Dovekie posted this in #help-forum
Open in Discord
Avatar
DovekieOP
Hello everyone,

I want to create some sort of singleton service in my NextJS application. Here's what I want out of it:

1. Be able to persist through re-renders, component changes etc. I only want it to die when the user closes the webapp
2. Expose some functions that can be used by components like startJob, pauseJob etc. I want to run these in button cilcks from the UI
3. I want it to keep some sort of state, with jobs that need to run and their status.
4. I dont want it to cause re-renders everytime it executes a function. So I'm wondering how will the components consuming it, be able to update their own state ? I'd like control over that, so let's say the state should be updated every 10s in one component for example.

0 Replies