Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow null value in TypeScript typing #347

Merged
merged 1 commit into from
Dec 11, 2020
Merged

Allow null value in TypeScript typing #347

merged 1 commit into from
Dec 11, 2020

Conversation

erikpuk
Copy link
Contributor

@erikpuk erikpuk commented Sep 26, 2019

Pretty trivial PR, but since you need to be able to set the value prop to null, seems like it should be allowed in the typings.

That said, the behavior itself did confuse me. This line specifically, where you ignore the value prop if it is undefined.... I guess you are using value={undefined} as a signal from the consumer that they want the NumberFormat to be stateful?

Might be better to have an explicit stateless prop. But maybe there's just some inevitable confusion when you can use the same component in either way.

I could add a bit to the readme about passing null if you are trying to use the NumberFormat as a stateless component.

@s-yadav
Copy link
Owner

s-yadav commented Oct 1, 2019

Nice catch.

I guess you are using value={undefined} as a signal from the consumer that they want the NumberFormat to be stateful

It's more of when value prop is not passed at all. Though value={undefined} will work. As null as a value also works for making an uncontrolled component in native inputs. We should update our codebase to add null check as well.

@erikpuk It would be great if you can update this PR to have null check as well.

@sarnendumukherjee
Copy link

@s-yadav Right now is there a way to set value as null. because setting the value as null is not permitted as per the typings but that works.

@s-yadav
Copy link
Owner

s-yadav commented Aug 31, 2020

@sarnendumukherjee I think passing null will break. https://github.com/s-yadav/react-number-format/blob/master/src/number_format.js#L152

We should check for null on this line as well. Would you like to give a PR for this?

@sarnendumukherjee
Copy link

HI @s-yadav , I created a small snip with an example of what am i trying to do and how it works but the TS will throw error and will not build as null is not a passable value for the value prop.
https://codesandbox.io/s/musing-haze-ddkuv?file=/src/App.js
You can change the initial value and try it out.
My worry is if we add the null check there this reset feature will stop working.
I was looking for a way to reset the value and setting the value as undefined does not reset the field.

s-yadav added a commit that referenced this pull request Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants