When clicked from the button component, I set the id
, then I pass this id
into the Redux-Toolkit Query request, but id
is initially null
. How can I do the check?
// id maybe null
const { id } = useSelector(userSelector)
const { data } = useGetUserQuery({ id });
Maybe props in up level.
If I'm correct in understanding that you really want to only make query requests for non-null
id
values then you can use askip
parameter or askipToken
to wait untilid
is non-null, or truthy.See Conditional Fetching
or
If you don't want the query to run for any falsey
id
value, e.g.null
,undefined
,""
,0
, etc, then the above can be simplified a bit.or