customInputProps with Typescript
See original GitHub issue <NumberFormat
customInput={TextField}
disableUnderline={true}
value={batch.price}
onChange={(ev) => {
setState({
...state,
batches: state.batches.map((bt, idx) => idx === index ? { ...bt, price: ev.target.value } : bt)
})
}}
decimalScale={2}
thousandSeparator="."
decimalSeparator=","
prefix="R$"
/>
I am using material-ui TextField input as a customInput. Problem is that I need to pass it some other props like disableUnderline, but this prop does not exist on NumberFormat and it makes the typescript compiles scream, although it works!
TS2322: Type '{ customInput: ComponentType<FilledInputProps>; disableUnderline: boolean; value: any; onChange: (ev: ChangeEvent<HTMLInputElement>) => void; decimalScale: number; thousandSeparator: string; decimalSeparator: string; prefix: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<NumberFormat> & Readonly<NumberFormatProps> & Readonly<{ children?: ReactNode; }>'.
Property 'disableUnderline' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<NumberFormat> & Readonly<NumberFormatProps> & Readonly<{ children?: ReactNode; }>'.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Creating a React Input component in Typescript
Here is a nice way to create a React Input component using typescript! Using an interface to declare your own prop types as...
Read more >How to create a reusable Input component with React ...
I don't think FC is satisfying the type constraint here, try ForwardRefRenderFunction instead: import React, { ForwardRefRenderFunction ...
Read more >Composing React Components with TypeScript - This Dot Labs
For our Input component, we need the following props : defaultValue , onChange , placeholder and name . Each of them is a...
Read more >Creating a React Input component in ... - Gisela Miranda Difini
Here is a nice way to create a React Input component using typescript! Using an interface to declare your own prop types as...
Read more >Typescript: register type on custom input #3382 - GitHub
With a component that looks like this, is there a way to get the register type from react-hook-form ? type props = {...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We have the same use case as @cescoferraro, a
customInputProps
prop would be nice.Our current workaround is:
I don’t think we need customInputProps to solve the typing issue, as we forward all the props to custom input. I liked the @Yankovsky solution to accept any other props. It does allow accepting any random prop, but I think for DX that tradeoff should be ok. @cescoferraro What do you think?
I have merged and released @Yankovsky PR on v4.1.0