defer useList load
Hi,
I'm using a code like this one
const [p, setP] = useState({})
const { isLoading, data } = useList(p);
useEffect(() => {
if (identity?.role === 'admin') {
setP({
resource: "retailers",
filters: [
{
field: "context",
operator: "eq",
value: "search"
},
{
field: "sortOrder",
operator: "eq",
value: "name"
}
]
})
}
}, [identity?.role])
The logic is that I need to load those retailers with useList only if the role is admin
The problem is that, as soon as the page loads, refine useList loads the endpoint with empty parameters, as the useList is outside the useEffect
BUT
I cannot put the useList hook inside an useEffect as I'm getting a conditional hook error...
how could I solve?
I'm using a code like this one
const [p, setP] = useState({})
const { isLoading, data } = useList(p);
useEffect(() => {
if (identity?.role === 'admin') {
setP({
resource: "retailers",
filters: [
{
field: "context",
operator: "eq",
value: "search"
},
{
field: "sortOrder",
operator: "eq",
value: "name"
}
]
})
}
}, [identity?.role])
The logic is that I need to load those retailers with useList only if the role is admin
The problem is that, as soon as the page loads, refine useList loads the endpoint with empty parameters, as the useList is outside the useEffect
BUT
I cannot put the useList hook inside an useEffect as I'm getting a conditional hook error...
how could I solve?
