score:3
Accepted answer
you should use uselazyquery hook in this case. it is very useful for things that happen at an unknown point in time, such as in response to a user's search operation.
how about if you call use your hook on the top of your function and just call it inside the useeffect hook.
const [search, { data }] = uselazyquery(search, {
variables: { "str": searchedtext },
pollinterval: 500,
});
react.useeffect(() => {
if (searchedtext)
search() // function for executing the query
if (data)
setsuggestions(data)
}, [searchedtext])
as you see, uselazyquery handles fetching data in a synchronous way without any promises.
Source: stackoverflow.com
Related Query
- Apollo React Why Can't Query inside UseEffect hook
- Apollo GraphQL query inside of react custom hook
- use query hook react Apollo conditional call
- React batch updates for multiple setState() calls inside useEffect hook
- Interval inside React useEffect - store it in a useRef Hook to preserve value overtime warning
- Access old state to compare with new state inside useEffect react hook with custom hooks usePrevious
- Why react `useRef` hook stores the objects in `current` property? Why cant it store directly in the ref object?
- Why React hook useEffect runs endlessly?
- <Query> vs graphql Hoc which is best way to hook graphql query with component in react apollo
- Assignments to the 'timeInterval' variable from inside React Hook useEffect will be lost after each render
- useEffect inside custom hook not getting called in correct oreder in React
- Why does useEffect React Hook not work properly with dependency?
- Testing Apollo Query with React Hook Client
- React / Apollo client: try to use LazyQuery in useEffect hook
- why do we need to put the onViewableItemsChanged prop inside a useRef hook in react native
- Why React JS useEffect hook is not refreshing the text?
- Cant access to method and property of an array inside React useEffect
- How to simplify an async call inside a React useEffect Hook
- React hook using useEffect with an array inside the dependencies array
- NextJs: Calling setInterval with a variable for time inside of a React useEffect Hook
- 'dataURI' variable from inside React Hook useEffect will be lost after each render
- Why does this custom React hook using useContext useEffect and setInterval fail in test
- React Hook useEffect has a missing dependency. Why am I getting this error when nothing is broken?
- React hook useCallback with get API call inside useEffect not behaving correctly
- Hook query retruning empty object inside useEffect but not after it Why?
- Assignments to the '[x]' variable from inside React Hook useEffect will be lost after each render
- Unable to push the URL with ID in react.js, React Hook useEffect has a missing dependency inside the array
- Enzyme unable to find children rendered inside React Apollo Query components
- Why I cant call useRouter hook inside getServerSideProps in next.js
- Why my React app runs firebase query in useEffect when I alter the database?
More Query from same tag
- Why cant I pass an objects string value into a API sorting function in React?
- how to use onChange attribute in dragger tag?
- React state is null inside of return
- Curious React behavior
- setState in $.get
- getting the Warning: React component classes must extend React.Component. on React
- Could not find react-redux context value; please ensure the component is wrapped in a <Provider> even if already wrapped in a provider
- react Todo list erases in console but does not erase from screen
- Resizing the Button of ReactBootstrap in ReactJS
- Avoid image blinking when back button is hit
- call parent function from child of child component react
- How to resize SVG shapes with mouse in React
- React Hooks addEventListener undefined
- Select component is ignoring parent onClick event
- Redux Saga not triggered/api not called - props undefined
- How to show different value returned from function for each rendered element from API in ReactJS?
- In React, how do you apply componentDidMount for this type of component?
- React Hooks: How could I fill a modal component after a button click?
- react-virtualized , where to call forceUpdateGrid to update table data?
- Making text field editable on button click
- nextjs getStaticProps not working in my component
- npm install @material-ui/core got error: Unexpected end of JSON input while parsing
- Detect click from an html element outside a React app and a react component
- Jest test on typescript file syntax error: "interface is a reserved word in strict mode"
- Rendering multiple classes/objects via React.js?
- Display No Record found message inside Bar Chart using Chart.js
- how can i return the values from one specific object?
- material-ui dropzone file reject on validation
- How to dynamically add class to parent div of focused input field?
- CardImg not loading in Reactstrap