English 中文(简体)
React Hook “useGetCatalogueDataByIdQuery”有条件地被称作。 处置 每一组成部分必须按完全相同的顺序排列。
原标题:React Hook "useGetCatalogueDataByIdQuery" is called conditionally. React Hooks must be called in the exact same order in every component render

除非目录存在,否则我就不需要所有复印件。

const GeneralInfoForm = ({ currentStep, setCurrentStep }: GeneralInfoFormValues) => {
  const user = getCurrentUser();
  const dispatch= useAppDispatch()
  // Mutation hook for adding catalogue info
  const [addCatalogueInfoMutation, { isLoading }] = useAddCatalogueInfoMutation();
  const CatalogueIdFromStore=useAppSelector((state)=>state.catalogueId.id)
  const { data} = CatalogueIdFromStore && useGetCatalogueDataByIdQuery({ catalogueId:CatalogueIdFromStore,queryParams:   });
  console.log(data,"from general info")

但它说的是:

React Hook "useGetCatalogueDataByIdQuery" is called conditionally. React Hooks must be called in the exact same order in every component render.eslintreact-hooks/rules-of-hooks
(alias) useGetCatalogueDataByIdQuery<UseQueryStateDefaultResult<QueryDefinition<any, BaseQueryFn<FetchArgs, BaseQueryApi, DefinitionType>, "brand" | "draftsTask" | "allEmployees", any, "baseApi">>>(arg: any, options?: (UseQuerySubscriptionOptions & UseQueryStateOptions<...>) | undefined): UseQueryHookResult<...>
import useGetCatalogueDataByIdQuery

如何解决这一问题?

问题回答

不用有条件地使用<代码>useGetCatalogueDataById Query,而只是添加一个附带参数,有条件地实施其逻辑。

  const { data } = useGetCatalogueDataByIdQuery({ catalogueId: CatalogueIdFromStore, queryParams:    }, {
    skip: !CatalogueIdFromStore
  });

在<条码>中 <代码>skip 价值和执行逻辑取决于此。

export const useGetCatalogueDataByIdQuery = (param1, param2) => {
  if (!param2) {
     // your logic
  }
}

你再次碰到的错误是,你根据CatalogueIdFromStore的价值,有条件地称使用GetCatalogueDataById Query。 必须无条件、按同样顺序,要求一切行为,以确保行为一致,避免ug。

因此,你可以创造一种习惯,避开目录数据,然后在您的InfoForm部分,将习俗称为:





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签