M
M
miliko mikoyan2019-06-07 12:57:13
typescript
miliko mikoyan, 2019-06-07 12:57:13

React Hook "useCategory" cannot be called inside a callback?

Here is my code

import React, { FC, useState,useMemo } from "react";

const FormSearch: FC<{ params: string }> = ({
   params 
}) => {
  const [category, useCategory] = useState<string>("All");
  const [search, setSearch] = useState<string>("");
  useMemo(() => {             
     const searchParams = new URLSearchParams(params);
    if (!!searchParams.get("Categories")&&!!searchParams.get("Search")) {
          useCategory(`${searchParams.get("Categories")}`); 
          setSearch(`${searchParams.get("Search")}`);   
    } else {
      setSearch("");
      useCategory("All")
    }
  }, [params]);

  return (
    <div>1000</div>
  );
};

I am getting these errors
Line 16: React Hook "useCategory" cannot be called inside a callback. React Hooks must be called in a React function component or in a custom React Hook function response-hooks / rules-of-hooks Line 20: React Hook "useCategory" cannot be called inside a callback. React Hooks must be called in a React function component or in a custom React Hook function to react to hooks/rules-hooks

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dev null, 2019-06-07
@miliko0022

This is a mistake about hooks. You have a category change handler that starts with use ...
rename it to setCategory

O
Ostic, 2019-06-07
@Ostic

Hook Rules

E
emp1re, 2017-07-09
@newaitix

mongodb.conf -> 27017 to 3306
Or better, change "mongodb://127.0.0.1:3306/mydb" to "mongodb://127.0.0.1:27017/mydb";

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question