flat-fuchsia
flat-fuchsia2mo ago

How to send a filter boolean in hook?

How to send a filter boolean in hook?
2 Replies
kapa.ai
kapa.ai2mo ago
Hi @tingadev. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To send a filter boolean in a hook using refine, you can use the filters property in various hooks such as useAutocomplete, useList, useCustom, and others. Below are examples of how to do this with different hooks: Using useAutocomplete You can send a boolean filter using the useAutocomplete hook as follows:
useAutocomplete({
filters: [
{
field: "isActive",
operator: "eq",
value: true,
},
],
});
useAutocomplete({
filters: [
{
field: "isActive",
operator: "eq",
value: true,
},
],
});
Source (https://refine.dev/docs/ui-integrations/material-ui/hooks/use-auto-complete/#filters) Using useList Similarly, you can use the useList hook to send a boolean filter:
import { useList, HttpError } from "@refinedev/core";

interface IProduct {
id: number;
name: string;
material: string;
}

const ProductList: React.FC = () => {
const { data, isLoading, isError } = useList<IProduct, HttpError>({
resource: "products",
filters: [
{
field: "isActive",
operator: "eq",
value: true,
},
],
});

const products = data?.data ?? [];

if (isLoading) {
return <div>Loading...</div>;
}

if (isError) {
return <div>Something went wrong!</div>;
}

return (
<div>
<ul>
{products.map((product) => (
<li key={product.id}>
<h4>{product.name}</h4>
</li>
))}
</ul>
</div>
);
};
import { useList, HttpError } from "@refinedev/core";

interface IProduct {
id: number;
name: string;
material: string;
}

const ProductList: React.FC = () => {
const { data, isLoading, isError } = useList<IProduct, HttpError>({
resource: "products",
filters: [
{
field: "isActive",
operator: "eq",
value: true,
},
],
});

const products = data?.data ?? [];

if (isLoading) {
return <div>Loading...</div>;
}

if (isError) {
return <div>Something went wrong!</div>;
}

return (
<div>
<ul>
{products.map((product) => (
<li key={product.id}>
<h4>{product.name}</h4>
</li>
))}
</ul>
</div>
);
};
Source (https://refine.dev/docs/data/hooks/use-list/#filtering) Using useCustom You can also send a boolean filter using the useCustom hook:
useCustom({
config: {
filters: [
{
field: "isActive",
operator: "eq",
value: true,
},
],
},
});
useCustom({
config: {
filters: [
{
field: "isActive",
operator: "eq",
value: true,
},
],
},
});
Source (https://refine.dev/docs/data/hooks/use-custom/#configfilters) These examples demonstrate how to send a boolean filter using different hooks in refine. You can adapt these examples to fit your specific use case. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@761921731505946634> kapa.ai is still learning and improving, please let us know how it did by reacting below