score:1
Accepted answer
if you really want to keep sticking to eslint suggestions and using the usequery
hook, here is an alternative way:
// component file
const history = usehistory();
const dispatch = usedispatch();
const q = usequery();
const [query] = usestate(q);
const [post, setpost] = usestate(null);
const [hash, sethash] = usestate(null);
useeffect(() => {
const fetchpost = async () => {
const hash = query.get("hashed_id");
const post = await fetchreviewpost(
`/api/posts/${hash}/review`
);
sethash(hash);
setpost(post);
};
fetchpost();
}, [query]);
at this point the query
value keeps constant across the subsequent function calls.
however, i'd remove the usequery
hook, and place its content straight into the fetchpost
function.
Source: stackoverflow.com
Related Query
- Why my custom hook causes infinite data refetching?
- Custom react hook causes infinite loop
- updating a useState to the value that it's already holding inside of a custom React hook causes infinite re-render
- why custom hook , context with useEffect lead to infinite loop?
- React: Infinite loop when using custom hook inside of useEffect?
- Setting state along with AsyncStorage in useEffect hook causes infinite loop?
- How can I mock return data from a custom hook in React/Jest?
- How to combine custom hook for data fetching and context?
- Fetch data with a custom React hook
- Adding dependency in useEffect hook causes infinite loop
- Refreshing data fetched with a custom hook after closing a modal
- Prevent infinite rerender of component custom hook
- Why do my fetch request causes an infinite error loop in ReactJs using React Toast Notifications
- Why is Setting state with data in a fetch using context API caught in an infinite fetch loop?
- Why creating a custom hook always triggers re-renderings and using useDispatch and useSelector directly do not?
- Why state doesn't keep all the data in Array state in hook when it updated in foreach?
- GraphQL defaulting data causes infinite loops in useEffect
- Why custom hook returns results twice
- REACT: How to create a reusable custom hook with functions and effects that can change & react to changes in a host component's data
- Why is jest not able to provide the useTranslation hook to a custom React hook I'm testing?
- Infinite loop in a custom useFetch hook
- Issues rendering data fetched with useEffect in a custom hook
- React form validation hook causes infinite re-render loop
- Why does a custom hook that uses another hooks value via useContext only shows its initial value?
- How to fetch data from a custom React hook (API) with onClick and display it in a Div using TypeScript?
- setState causing infinite loop in custom hook
- Custom hook when taking data in next render lost data
- Submit a form with data using a custom React hook
- react (next) wait context data and passing values to custom hook
- Can't map fetched data from custom useFetch() hook
More Query from same tag
- React Hamburger Menu unfunctional
- Set JSON object to a Const on material UI Select component React Hooks
- Loader is not showing during paging or filtering in MUIDatatable
- Storing global data with socket.io
- react getting observable values in component
- Multiple async XMLHttpRequests in React
- Typescript useState hook on an object does not save
- Webpack + React: Webpack builds from my node_modules folder in correct order in one place, and incorrect order anywhere else
- Error running a Jest snapshot test using a custom snapshot serializer - jest-styled-components
- Reactjs create multiple object array declaration
- Delete dynamically added table row - react js
- min-height property with nested react components?
- How to set border radius ant design
- Performance issue with React
- Fire event listener on element not rendered in React
- Redirect using navigate() to the same URL updating the state in react
- How to select nodes for Enzyme testing when class names are not static?
- How to send error messages from express to react/redux
- string containing white space or not in react
- Passing an icon component to another component in ReactJS
- React app runs locally, crashes when on Heroku error code=H10
- How can I get the height of an element after it has rendered?
- React JS: Pass A value from route to component
- I'm getting this error "TypeError: Cannot read property 'map' of undefined" on my React project
- Apply types in React ant design
- React render function preventing creating new canvas element on each time invoked - Charts.js
- React with Firebase - submitting Formik form data
- gatsby & graphql : filtering for a specific single image
- React context API - can't update parent consumer from child provider
- Styled component not wrapping another styled component