J
J
JeyFom2021-10-15 15:57:47
React
JeyFom, 2021-10-15 15:57:47

What is the difference between these redirects in React?

There are two applications, one is used for redirect

const history = useHistory();
history.push(url);


in another application
import { push } from 'connected-react-router';
...
dispatch(push(url));


What is the difference between these approaches? Perhaps the second one is used in some specific cases? Reading the documentation did not give a complete understanding

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2021-10-15
@JeyFom

In the first case, the editor knows nothing about the router, the router is used by itself. In the second case, the router is attached to redax and the logic is wrapped in a middleware from connected-react-router. There is no difference in components. The difference is that the second method allows you to work with the router through special action dispatchers where there is no react - for example, in redux-thunk or redux-saga.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question