A collection of custom React hooks
npm install konciv-hooksThe useSearchData hook is a custom React hook designed to fetch and manage search data efficiently. It allows you to filter, sort, and retrieve items based on various customizable criteria such as item types, properties, location, and more.
---
Make sure you have all the necessary dependencies installed in your project before using this hook.
``bash`
npm i konciv-hooks
---
`javascript`
import { useSearchData, useApi, useSearchItem } from "konciv-hooks";
Here’s how you can use the useSearchData hook in a functional React component:
`javascript
import React from "react";
import { useSearchData, useApi, useSearchItem } from "konciv-hooks";
const SearchComponent = () => {
const token = "your-auth-token"; // Replace with your actual token
const ocpKey = "your-ocp-key"; // Replace with your actual ocpKey
const { itemTypes, projects, globals, users, groups } = useApi(token, ocpKey); // Exclude or include whatever you need. Only does api for whats in the object.
const { data: nameWhateverUWant, error: searchItemError, loading: searchItemLoading } = useSearchItem(token, ocpKey, itemId);
const { searchData, allDataFetched, error, loading } = useSearchData({
token: token, // Required
ocpKey: ocpKey, // Required
itemType: itemTypes?.employee, // To seach withing item type "Employee" - Required
itemName: "Hello", // Search by item with a name "Hello" - Optional
properties: [
{ name: "User", value: "E3GRG342-GJ123-4567890" },
{ name: "Monthly Salary", value: "40000" }, // By Default its EQ on numbers.
{ name: "Recieved", value: "200000", comparison: "GOE" }, // On number properties u can use comparions: "GOE", "LOE", "EQ", "NEQ" and so on.
{ name: "Process Step", value: "Ready for Project", operator: "OR" }, // You can add operator "OR/AND" on each property.
], // Filter by custom properties - Optional
location: {
// Optional
locationName: "Tananger",
subregionName: "Stavanger", // Optional
},
pageSize: 4200, // Number of items to fetch ""all" || number" - Optional. 2000 is default.
propertyOperator: "AND", // Filter operator (AND/OR) - Optional. AND is default - Optional.
});
if (loading) return
return (
All data fetched successfully.
}export default SearchComponent;
`
---
The useSearchData hook accepts an object with the following options:
| Option | Type | Description |
| ------------------ | ----------------- | ----------------------------------------------------------------------------------- |
| token | string | Required. Authentication token for API access. |ocpKey
| | string | Required. Key for additional API security. |itemType
| | Array | Optional. List of item types to filter the search results. |itemName
| | string | Optional. Name of the item to search for. |properties
| | Array
---
The hook returns an object with the following:
| Property | Type | Description |
| ---------------- | --------------- | --------------------------------------------------------- |
| searchData | Array
- Ensure proper error handling is implemented for smoother user experience.
- Adjust the pageSize` to balance between performance and result accuracy.
- Customize the filters based on your specific use case.