New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

zfstore

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zfstore

A tiny factory function to create a Zustand store with Feathers.js integration for API calls.

latest
Source
npmnpm
Version
2.0.4
Version published
Maintainers
1
Created
Source

Zustand + Feathers Store

A tiny factory function to create a Zustand store with Feathers.js integration for API calls.

Installation

npm install zustand feathers axios zfstore

Usage

//lib/stores.js
import { storeFactory } from 'zfstore';

// Create store with default Feathers app and URL
export const useApiStore = storeFactory();

// Or with custom configuration
import app from './app.js'
export const useCustomStore = storeFactory(app, 'https://api.example.com'); //make sure CORS is enabled for third party APIs.

In your react component:

// components/MyComponent.jsx
import { useApiStore } from './lib/stores.js';

export default function MyComponent() {
  //service name variable is automatically added.
  const { loading, error, api, todos } = useApiStore();
  
  const fetchData = () => {
    //service name, service method, optional args as required by your feathers service API.
    api('todos', 'find', { query: { completed: false } });
    //or
    //let id = 1;
    //api('todos', 'get', 1);
    
    //let data = { title: "some todo" }
    //api('todos', 'create', data);
    //api('todos', 'update', id, {completed: true});
    //api('todos', 'patch', id, {completed: true});
    //api('todos', 'remove', id);
  };

  useEffect(() => {
    //no need to add async :')
    api('todos', 'find', { query: { completed: false } });
  }, [])

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error}</div>;

  return (
    <div>
      <button onClick={fetchData}>Reload Todos</button>
      <ul>
        {todos?.data.map(todo => (
          <li key={todo.id}>{todo.text}</li>
        ))}
      </ul>
    </div>
  );
}

The store's state will contain a variable with the name of the service that you called. So here, todos will be available, and updated when new calls are made from the client.

Store API

interface StoreState {
  loading: boolean;
  error: string | null;
  [service: string]: any; // Service data
}

const store = useMyStore();

// Example API call
store.api('todos', 'find', { query: { completed: false } });

Notes

  • Error messages are stored in state for client-side handling
  • Loading state is automatically managed

Keywords

zustand-feathers

FAQs

Package last updated on 03 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts