score:1
Accepted answer
you need to move the hook out of the event handler, and in to the body of the component.
import react, { usestate } from 'react';
import usefetchngsdata from '../usefetchngsdata';
const data = (props) => {
const { data: players } = usefetchngsdata('/league/roster/current?teamid=5100')
return (
<div>
// ... handlegetplayers
</div>
);
}
export default data;
but really, you don't need to use setplayers here. you already have that data in your returned values from your custom hook.
Source: stackoverflow.com
Related Query
- How can I mock return data from a custom hook in React/Jest?
- How to fetch data from a custom React hook (API) with onClick and display it in a Div using TypeScript?
- How do I return data from a custom react hook?
- How to enrich data from custom react hook
- How to retrieve data from custom attribute on option tag in React
- How to return mutated values from a custom React hook?
- REACT: How to create a reusable custom hook with functions and effects that can change & react to changes in a host component's data
- How to return json data from 400 error to React from Express?
- How to create custom validation from react hook form?
- How to mock react custom hook return value as a module with Jest
- React hook form how to pass value from custom component to controller with already assign own on change?
- How do I fetch data in a React custom hook only once?
- Custom hook to get data from store, if no then dispatch action and return data
- How to set data from a react hook inside of a function or event?
- How to pass state data from custom hooks to react component?
- How to properly export a component from a React custom hook and a function to control it?
- How to reuse data fetching logic from api using react custom hooks
- How to return custom component from another function in react JS?
- How to use the return value from React hook updater function?
- Early return from react useEffect custom hook is not getting destructure
- How to inject parameters into return function with custom hook react
- how to return a function from react hook which internally uses a promise to get the value
- How to mock data from service as hook with React Testing Library?
- How to get return data from another file outside of a react component?
- How to return boolean value from custom function in react
- How to sto React useEffect hook from rendering duplicated data
- How to fix zero return data from itunes api using react fetch
- React Hook : Send data from child to parent component
- How to mock react custom hook returned value?
- How to get the data from React Context Consumer outside the render
More Query from same tag
- Eslint treating string as array in React component
- Is there a way to tell WebdriverIO to wait for background tasks in react app
- React: Higher Order Components: Can you can childs state
- Why handleClick event is not fired from Child Element?
- Testing Failure: ReferenceError: SpeechSynthesisUtterance is not defined
- How to export a global object in React js
- SelectField to display a string different from the value
- How to pass string parameter to nested function, which has already parameters?
- Should I Create Functions Inside The Component or Put Them In The State (Zustand)
- Dropdown menu - disappear after clicking on item
- Pass argument to react method correctly
- Rendering three.js element in React?
- When I use the `hreflang attribute in Link I get warning
- Are there ways by which we can improve the performance of a React App when it has 2 awaits in the useEffect?
- Typescript React UseReducer Type Error on Provider Value
- Route static not working
- Remove React components that throw an error from a grid
- React typescript error Parsing error: '>' expected
- how to set miliseconds to date format inside a map in react?
- Test state value after promise resolved
- React Event Handler. Adding values to array
- Ignore some installed packages in webpack
- Change id of multiple item of array React
- Passing React Router Link "to" parameter as props
- Difference between this useReduxState hook and useSelector in terms of performance?
- Separate API calls using dispatch from redux-forms "onSubmit"
- How can I update model In Show component
- Why is my effect running multiple times, slowing the application after a few sends?
- How do I use environment variables or mask secrets in package.json?
- Is fullscreenchange event supported in React?