score:1
use a generic:
const useform = <t extends record<string, any>>(initialstate: t) => {
const [form, setform] = usestate(initialstate);
const handlechange = (e: react.changeevent<htmlinputelement>) => {
e.persist();
setform((f) => ({ ...f, [e.target.name]: e.target.value }));
};
const onsubmit = (e: react.formevent<htmlformelement>) => {
e.preventdefault();
};
return { form, handlechange, onsubmit } as const;
};
Source: stackoverflow.com
Related Query
- How to pass in any object for custom hook react
- How to pass an object to onSubmit in React Hook Form
- How to pass react hook state to another component for each click
- How to render custom elements for each item in an object (Map data structure) in React TS?
- how to create a custom hook on react for this current useState usage
- How do I pass additional dependencies to a React custom hook
- React hook form how to pass value from custom component to controller with already assign own on change?
- How to access React router history object with component interface that has default custom hook specified
- How to pass as prop for a React Element an object that has a huge number of properties?
- How do I pass an object (created by a buttonClick event) from child to parent in react when already using props for a styled button
- How pass an object to a child custom React functional component with Typescript
- Warning: Received `false` for a non-boolean attribute. How do I pass a boolean for a custom boolean attribute?
- How to mock react custom hook returned value?
- How to handle dependencies array for custom hooks in react
- React useReducer Hook fires twice / how to pass props to reducer?
- How to mock a custom hook inside of a React component you want to test?
- how to create React search filter for search multiple object key values
- How to set React default props for object type
- How to memoize custom React hook
- How do you set the Typescript type for useRef hook in React Native?
- How do I pass an object containing props to React component?
- How to create type definition for the React useReducer hook action in Typescript?
- ESLint rule for Object & array dependencies in the React useEffect Hook
- Drag and Drop in React.js. How to pass custom react component in setDragImage
- Any reason for a react state hook set callback to fire twice?
- How to wait for React useEffect hook finish before moving to next screen
- How can ı pass function with state for react useContext
- ReactJS + React Router: How to reference a specific object to pass down as properties?
- How to combine custom hook for data fetching and context?
- How to validate password and confirm password in react hook form? Is there any validate property and message in react hook form to show errors?
More Query from same tag
- Getting key prop warning in React, even though key is set
- React router this.props.history.push , pushing the location but not rendering the component
- normal graphql queries causing errors
- Create React App SyntaxError: Unexpected Token
- Validation check in reactjs issue
- Using React.ComponentProps in a generic function
- How to get the details of input text and send it to bacend in ReactJs
- Confusion on React Callback's on Forms
- How to wire up redux-form bindings to the form's inputs
- React-router + electron Location "/" did not match any routes
- "Cannot use import statement outside a module" error when importing react-hook-mousetrap in Next.js
- styled-components toggle classes
- Populate a dropdown from an API using Reactstrap
- react plotly js with typescript
- filtering a mapped object based on React Router
- React jest test with enzyme error
- 403 OPTIONS Cors error in AWS, preflight requests
- Do variable values in useEffect's cleaning function remain as they were in the last time useEffect ran?
- Objects are not valid as a React child (APIs, JSON)
- How can I move the green text under the image?
- React/Redux controlled input with validation
- Checking looped radio buttons
- How to pass state from child to parent with Hooks
- Parsing different inputs in multi-part forms - React form
- Redux axios action include variabel params in request from function
- Why is my login component not redirecting successful login's to the right page?
- How to fix 'TypeError: Cannot read property 'id' of undefined' error in NextJS?
- Selecting something that isn't a div or other standard selector?
- Multiselect not working when array is initialized
- How to disable form autocomplete in semantic-ui-react?