score:1
Accepted answer
as the error says, you can't have useeffect
called conditionally. instead, call it a single time regardless, and inside that function, look to see whether you need to fetch the clips or the comments.
useeffect(() => {
if (boolean) {
fetch("/clips")
.then((r) => r.json())
.then((data) => setclipdata(data));
// don't forget to .catch errors here
} else {
fetch("/most_comments")
.then((r) => r.json())
.then((data) => setclipdata(data)); // did you mean to call setcommentsdata or something here?
// don't forget to .catch errors here
}
}, []);
Source: stackoverflow.com
Related Query
- Conditionally render useEffect fetch React
- Make React useEffect hook not run on initial render
- React fetch data in server before render
- React conditionally render based on viewport size
- Does a render happen before function in React Hooks useEffect is called?
- Is it better practice to conditionally render in React or conditionally add a class to hide elements
- React useEffect hook and Async/await own fetch data func?
- React - conditionally render multiple elements
- React useEffect dependency of useCallback always triggers render
- Using fetch to render json data in react app
- Is there a clean way to conditionally load and render different components for the same React Router route?
- React Hook useEffect : fetch data using axios with async await .api calling continuous the same api
- How to conditionally render a DIV and REACT component for OPENING and CLOSING tags?
- How to fetch data without useEffect hooks in React function component?
- React Hooks : fetch data inside useEffect warning
- React Native conditionally render part of view while input is focused
- Conditionally render multiple elements inside a react fragment
- React useEffect hook load onsnapshot conditionally
- React Component to render children conditionally not working as I want it to
- How to conditionally render a React component that uses hooks
- Assignments to the 'timeInterval' variable from inside React Hook useEffect will be lost after each render
- React useEffect infinite loop fetch data axios
- How to conditionally render error in react js?
- Fetch data and then render it to dom React
- React Page Scrolls on top after re render by useEffect
- How to fix my React Context to render useEffect and reload table data
- React hook useEffect causes initial render every time a component mounts
- React Hooks useEffect Change Fetch URL Call
- react hook useEffect to fetch data on button click (typescript)
- React router Link to conditionally render button
More Query from same tag
- How to combine inline style and external import const style in JSX React
- How can I use createContext with TypeScript?
- Render array of object React
- How to mock window.gapi.load() React + Jest
- Designing a star pattern in React Native
- React hooks dependencies, including it creates an infinite loop, not including it doesn't give me the latest value
- How can I make my Material Icons change color when I hover over them?
- Django csv output with react
- Globals with Browserify / ReactJS
- express js sendfile and download in react client
- Formik Field not clearing after form submit
- How to handle the `onKeyPress` event in ReactJS?
- I try to show a name in the url in react
- How to get selected values from multiple dropdowns on button click using ReactJs
- Removing Null nested fields in Django Serializer --- or how to iterate with Null?
- Using Material-UI's useStyle in helper functions or making helper functions behave like functional components
- findDOMNode warnings with CSSTransition components
- React Hooks onClick in list item
- Post request with axios and redux-thunk in a redux-form
- React : Setting scrollTop on Div doesn't work in a specific case
- React Typescript fetch: useState UseEffect pokeapi
- Type '{ author: Author; }' is not assignable to type 'IntrinsicAttributes & Author'
- How can I use fetched const value in react?
- React, how to get data after clicking on checkbox?
- Insert object into array at specific index in React
- ReactiveSearch only autocomplete
- Delete particular data in mongodb using node js
- Apollo Client - fetchMore component update problem
- Line 30: 'React' must be in scope when using JSX when it is deploying on heroku
- Splicing into array of objects using setState update helper and event targets only works with initial array index and fails with all others