score:0
right now your useeffect is triggered each time your component mount so basically when someone reaches this screen. at this time your query state is empty.
try adding this :
useeffect(() => {
const getfiltereditems = async (query) => {
let response = await fetch(apiurl+query);
let papers = await response.json();
setapidata(papers);
if (!query) {
return papers
}
return papers;
}
getfiltereditems(query);
},[query]) - - - - > here
by doing so, your useeffect will be triggered only and each time your query state changes
score:0
you should either include query in your dependency array i.e., second argument of your useeffect hook or either remove. when it's(array) empty useeffect will only render once i.e., when your page render for first time but when removed useeffect runs both after the first render and after every update. when specified like you put 'query' in dependency array it will only run whenever there is change in 'query' state.
Source: stackoverflow.com
Related Query
- How can I use a useState variable inside uesEffect?
- React - How to use the current state value as a variable so i can set as a index inside an array
- How can I use breakpoints inside createMuiTheme? Material UI & React.js
- How can I get rid of a URL in a fetch (to use kind of a variable instead)?
- how can we use redux state in useState to set initial values
- How can I use an axios get call inside a Context provider in react
- How to use an ejs variable inside a react render function?
- How can one use a polymer component inside a react component ? Is it possible?
- How can i use Jest to test a function inside a stateless component?
- How can I use an asynchronous javascript function like fetch inside a FormDataConsumer
- How can you use the 'this' keyword inside of a function signature to set a default parameter?
- How can I convert a string to a number inside of a useState Hook?
- How can I use the useState function as a toggle method?
- Can you use useState hook inside onClick function?
- How to use "if" inside useState prevState map
- how to use two useState in one function so that the second useState can use the first updated useState?
- How react functional component can use object variable which declared behind the usage? (include example)
- How can i access variable inside useEffect() hook
- How i can use the handleSubmit inside my component?
- How can I declare a variable inside brackets?
- How can i use {useState} inside ComponentDidMount in ReactJS
- can I use variable declared within a function as a parameter for another function nested inside the function?
- How can I use React Router's withRouter HOC inside my own higher order component (HOC)?
- How to use a variable in which data is fetched from mongoDB , in another file where we can use the data stored in that variable
- REACT: How to use a variable defined inside .env file?
- How can I access a value of a variable inside a map function?
- Why inside a function you can use a variable that's declared later
- how to use useState inside inner function scope in react.js hooks
- How can I use the varible inside array map to control style on Material UI?
- How can I use moment() library inside a non-react module (for a React project)?
More Query from same tag
- parsing failed SyntaxError: Unexpected end of input
- Changing specific index of an array in state instead of all of my state object
- Unsorted table data is rendered along with sorted data in table
- Define firebase data structure with TypeScript
- gatsby-plugin-sitemap Putting trailing slash to homepage only
- How to set OTP timer on button click in react JS?
- How to remove highlight from menu item hover in Ant Design?
- Disconnect wallet from site using web3
- Dynamic CSS via prop using CSSModules with React component
- How can I iterate over an array of json object in Reactjs?
- How to trigger a function at regular intervals of time using hooks and when certain criteria is met I want to clear the time interval?
- React Navigation switching background colors and styling StackNavigator
- How can i position a logo image from a list react component?
- Dynamic Routing Reactjs
- Render not being called after state gets updated
- (React) How to make checkbox UI look checked after mutating state?
- Using props of a passed component
- Can JS components inherit CSS style?
- Uploading ReadableStream as part of FormData from Browser
- React Router with Meteor: How to remove code param from URL after redirect from OAuth without reload
- onChange event inside loop is only passing 0th index
- How to update ReactJS component based on URL / path with React-Router
- TypeError: Cannot read property 'edit' of undefined in reactjs
- How to pass an Array from Child component to Parent component using hooks in react
- React-Typescript: Expected an assignment or function call and instead saw an expression
- How to update certain object in state array based on received key from DOM
- Converting XML data to JSON on ReactJs
- Click on a component to navigate to another page
- Reactjs react-router-dom
- How specify the number of datalist's rows to be shown in react