When route changes basically component unmounts.And you cannot control local state of unmounted component.
But you can update redux state when component unmounts.
useEffect(() => {
return () => // your dispatch function
}, []);
But if component does not unmount just paste update function in useEffect
without return keyword.
useEffect(() => {
dispatch(someFunc()); // when search updates this will be call
}, [search]);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…