Answer the question
In order to leave comments, you need to log in
Is it bad if the redux action works "for nothing"?
Good afternoon. I'm trying to implement autocomplete for a search string. And according to the idea, when someone clicks on the result that has dropped out from the autocomplete, there is a transition to the corresponding page (the path in the router). In this case, the value of the input with the search should be reset to zero, as well as the array in the editor, to which the search results come.
I use hooks and couldn't think of anything better than checking location.pathname in useEffect:
const [inputValue, changeValue] = useState('');
useEffect(() => {
return () => {
changeValue(''); // обнуляет значение инпута
fetchSearch(''); // это экшен. Если придет пустое значение, то он обнулит массив с результатами поиска
}
}, [location.pathname, fetchSearch]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question