question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Robfzcommented, Mar 25, 2019

We have the same use case as @cescoferraro, a customInputProps prop would be nice.

Our current workaround is:

const CustomInput = ({ customInputProps, ...inputProps }) => { ... }

...

// @ts-ignore
<NumberFormat
  value={value}
  customInput={CustomInput}
  customInputProps={someProps}
/>
2reactions
s-yadavcommented, Aug 5, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found