0

I have some component

import { RouteComponentProps, withRouter } from 'react-router';
function MySearchComponent({ match, location, history }: RouteComponentProps) {
  const [query, setQuery] = useState<string>('');
  useEffect(() => {
    console.log('all fine!')
    history.replace(`/my_search_page?query=${query}`);
  }, [query]);
  // some code for change query
}

export const MySearch = withRouter(MySearchComponent);

What's wrong? I'd tried to use history.push console.log alter right when query changed, but nothing happend

UPD: Sorry. It was my mistake: my application just doesn't support search-parameters Thanks for your help

2
  • console.log() is not called? Could yo put some more code? Are you sure that query changes? Commented Sep 23, 2020 at 19:13
  • Yes, it's called fine and yes query is changed Commented Sep 23, 2020 at 20:14

1 Answer 1

2

In my application I am using useHistory hook

import React, { useEffect } from "react";
import { useHistory } from "react-router-dom";

const Operations = () => {
  const history = useHistory();

  useEffect(() => {
    const res = prepareURLParams(filters);
    history.push(getRouterString("/", res));
  }, [filters]);
}

export default Operations;
Sign up to request clarification or add additional context in comments.

4 Comments

@NachoZullo I was reading this article medium.com/@Charles_Stover/… and found this text "react-router's built-in withRouter HOC does not re-render components on route change, " Maybe this make sense...
Sorry. It was my mistake: my application just doesn't support search-parameters Thanks for your help
@Dmitry What kind of application does not support query(search) parameters? Is it mobile application?
@Alexey My web-application is a tiny microservice worked in a large web application. I tried to change url on /blah-blah-blah without search-parameters and it's work fine. Looks like a search-parameters cutting from url in the base component

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.