score:0
use generics
function handlechange<t extends htmlelement>(key: keyof formstate) {
// e: any could work here but i would like to avoid that if possible
return (e: react.changeevent<t>) =>
setfields((fields) => ({ ...fields, [key]: e.target.value }));
}
Source: stackoverflow.com
Related Query
- React custom change event handler in form hook
- React (Next.js) cannot get click event in a custom hook to change state of parent component
- React useState hook event handler using initial state
- Calling custom hook in event handler
- How to trigger a custom hook on onClick event in react
- React hook is not working from event handler
- React Hooks: Idiomatic way to ensure that useEffect runs only when the contents of an array argument to the custom hook change
- Custom onChange for React Hook Form and watch()
- React custom hook with event listener not works while updating the state
- React submit form on select change event
- REACT: How to create a reusable custom hook with functions and effects that can change & react to changes in a host component's data
- React Strictmode preventing a custom made useState hook to change the state at the first call
- Run event handler functions synchronously after a React state change
- Custom react hook to set input form not working
- Submit a form with data using a custom React hook
- Problem with useRef React Hook and event listener and change img src
- React hook form how to pass value from custom component to controller with already assign own on change?
- Invoke React custom hook on form submit
- React Hook Form OnSubmit Handler and Validation
- React does not change state after updating state in usestate hook (in custom function form)
- use react hook form with custom TextInput
- Login Form React JS With Custom Hook
- How to disable a button using React useState hook inside event handler
- React Custom Hook make return Function executable on an Event
- Form Using React Hook Forms showing undefined for Custom Input Component Fields
- React Hook Form validation using nested custom checkbox component
- React custom hook to to log page render start event
- react custom hook parent handler is not keeping custom hooks state
- React state not updating after one time change through event handler
- Use debounce inside a custom React hook for input change
More Query from same tag
- reactjs onChange not picking up last character
- Can I append div on button click in react?
- how can I setState in unmount Component in React
- Problem in Link and to in react and react router
- Socket.io not emitting messages to a specific user
- Making an API call through external file and returning results React
- React property destructuring in the constructor. Is a good idea?
- ReactJS How to prevent multiple API calls occurring in componentDidMount function
- How can I see post body data in chrome dev tools?
- Obtaining the react-calendar value once it is passed to another component
- Implementing The SliderPicker from react-color library
- Unfamiliar with this javascript syntax that I came across
- How to pass value of state variable from one component to a sibling component?
- Why does this inputs value keep giving me undefined?
- Then and Catch not running on successful Axios Post request on Backend
- How to get Date and Time in Firebase Timestamp in react js
- Dynamically creating canvas height for image display
- React Hook "useState" cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function
- Do I have to wrap components in html tags?
- How to add ids to every element of an array in JavaScript?
- Throttling on keypress events in Javascript
- Making a clickable SVG that doesn't trigger a mouseLeave
- Material-ui Autucomplete: specifying custom CloseIconButton
- Alternative to setInterval that consumes less resources
- Why does react Apollo on update subscription returns the already updated value as prev?
- How can I fix this error in react related to react-router
- SPA 404 on Refresh: Go+React App on Heroku
- API request error - No 'Access-Control-Allow-Origin' header is present on the requested resource
- Why giving dynamically a src to a new Image() object sometimes give width and height 0
- moment-timezone.js – Getting Error When Running in Jest Test