Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@peable/services

Package Overview
Dependencies
Maintainers
1
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@peable/services - npm Package Compare versions

Comparing version 0.0.18 to 0.0.19

7

dist/hooks/getUserById.d.ts

@@ -8,8 +8,9 @@ interface User {

}
declare const useGetUsersByIds: (ids: string[], fields?: (keyof User)[]) => {
users: User[] | null;
declare const useGetUserById: (fields?: (keyof User)[]) => {
user: User | null;
status: "loading" | "loaded" | "error" | "idle";
error: string | null;
getUser: (id: string) => Promise<void>;
};
export default useGetUsersByIds;
export default useGetUserById;
//# sourceMappingURL=getUserById.d.ts.map

@@ -1,39 +0,29 @@

import { useState, useEffect } from "react";
import { useState } from "react";
import axios from "axios";
const useGetUsersByIds = (ids, fields) => {
const [users, setUsers] = useState(null);
const useGetUserById = (fields) => {
const [user, setUser] = useState(null);
const [status, setStatus] = useState("idle");
const [error, setError] = useState(null);
useEffect(() => {
const getUsers = async () => {
setStatus("loading");
try {
const responses = await Promise.all(ids.map((id) => axios.get(`http://localhost:3001/api/users/${id}`, {
withCredentials: true,
})));
const users = responses.map((response) => {
const user = response.data;
return fields
? fields.reduce((obj, key) => ({ ...obj, [key]: user[key] }), {})
: user;
});
setUsers(users);
setStatus("loaded");
const getUser = async (id) => {
setStatus("loading");
try {
const response = await axios.get(`http://localhost:3001/api/users/${id}`);
const user = fields
? fields.reduce((obj, key) => ({ ...obj, [key]: response.data[key] }), {})
: response.data;
setUser(user);
setStatus("loaded");
}
catch (error) {
if (axios.isAxiosError(error)) {
setError(error.message);
}
catch (error) {
if (axios.isAxiosError(error)) {
setError(error.message);
}
else {
setError("An unknown error occurred while loading the user data.");
}
setStatus("error");
else {
setError("An unknown error occurred while loading the user data.");
}
};
if (ids.length > 0) {
getUsers();
setStatus("error");
}
}, [ids, fields]);
return { users, status, error };
};
return { user, status, error, getUser };
};
export default useGetUsersByIds;
export default useGetUserById;
{
"name": "@peable/services",
"version": "0.0.18",
"version": "0.0.19",
"description": "",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc