I have a useEffect
function Component () {
const facets = useSelector(getFacets)
useEffect(() => {
dispatch(search(facets, param2, param3))
}, [dispatch, facets, param2, param3])
//rest of component with return
}
now search will actually update that facets
//Inside my slice
const search = (facets, param2, param3) => async(dispatch) => {
//do a fetch using param2 and param3
//fetch comes back with a facets object
//alter response facets object based on 'old' facets
dispatch(setFacets(newFacets)) // set the new facets
}
The issue is, when this useEffect runs, the re-render causes const facets = useSelector(getFacets) to load a new value... Linting requires I have facets as a dependency in the useEffect but putting it there means it'll just loop over and over again. How do I stop it?
I've tried pulling the logic out of a useEffect and putting it in a useCallback, but again, linting requires that I put facets as a dependency, which is basically the same exact issue.