score:1

Accepted answer

if you really want to keep sticking to eslint suggestions and using the usequery hook, here is an alternative way:

  // component file 
  const history = usehistory();
  const dispatch = usedispatch();
  const q = usequery();
  const [query] = usestate(q);
  const [post, setpost] = usestate(null);
  const [hash, sethash] = usestate(null);

  useeffect(() => {
    const fetchpost = async () => {
      const hash = query.get("hashed_id");
      const post = await fetchreviewpost(
        `/api/posts/${hash}/review`
      );
      sethash(hash);
      setpost(post);
    };

    fetchpost();
  }, [query]);

at this point the query value keeps constant across the subsequent function calls.

however, i'd remove the usequery hook, and place its content straight into the fetchpost function.


Related Query

More Query from same tag