grumpy-cyan
grumpy-cyan3d ago

useOne did not recall when id from useParsed change

useOne did not recall when id from useParsed change
3 Replies
kapa.ai
kapa.ai3d 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: ---------------------- Based on the knowledge sources provided, there isn't enough specific information to directly address the issue of useOne not recalling when the id from useParsed changes. However, I can provide some relevant information and a potential workaround based on the available documentation. The useOne hook is designed to fetch a single record from an API endpoint. It typically uses the id parameter to determine which record to fetch. When using useOne with useParsed, you might encounter issues if the hook doesn't automatically react to changes in the id. A potential solution to this problem is to manually control the id passed to useOne using the setId function. This approach is mentioned in the useForm documentation:
import { useForm } from "@refinedev/antd";
import { useParsed } from "@refinedev/core";

const { id } = useParsed();

const { setId } = useForm({
resource: "custom-resource",
});

setId(id);
import { useForm } from "@refinedev/antd";
import { useParsed } from "@refinedev/core";

const { id } = useParsed();

const { setId } = useForm({
resource: "custom-resource",
});

setId(id);
By using this method, you can ensure that the id is updated when it changes in the URL. Alternatively, you could consider using the queryOptions parameter of useOne to control when the query should run. For example:
const { id } = useParsed();

const { data, isLoading } = useOne({
resource: "products",
id,
queryOptions: {
enabled: !!id,
},
});
const { id } = useParsed();

const { data, isLoading } = useOne({
resource: "products",
id,
queryOptions: {
enabled: !!id,
},
});
This approach ensures that the query only runs when there's a valid id. If these suggestions don't solve your specific issue, you might want to consider creating a GitHub issue for the Refine project, as this could potentially be a bug that needs to be addressed by the Refine team. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3d ago
<@761921731505946634> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
wise-white
wise-white2d ago
Hello @tingadev, can you provide reproducible example please? In my tests, it's worked . maybe I couldn't recreate the problem

Did you find this page helpful?