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.

value gives [object Object] if inputComponnent={Input} and this Input is imported from "@material-ui/core"

See original GitHub issue
<PhoneInput
              inputComponent={TextField}
              limitMaxLength
              value={phone}
              onChange={value => this.handlePhone(value)}
              error={phone ? (isValidPhoneNumber(phone) ? undefined : 'Invalid phone number') : 
'Phone number required'}
 />

Neither TextField not Input from material-ui/core works fine. Your component works perfectly fine but when we use Input from material-ui, it starts giving [object Object] in value where expected value is the entered phone number. Please help!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
catamphetaminecommented, Oct 16, 2019

@TylerRick

I finally found the solution to this problem (getting [object Object] as the value) that @mghazanfar and I were having, in the comments on #226

And I finally figured out that indeed inputComponent isn’t what I initially thought it was when replying in this issue. Lol. Indeed, just swapping inputComponent isn’t enough. I’ve added a new numberInputComponent property — this one is swappable and could be set to a Material UI input or whatever else.

Released react-phone-number-input@2.3.25 with the numberInputComponent property.

0reactions
TylerRickcommented, Sep 25, 2019

Thank you so much for your reply and suggested workaround. I don’t think we even need to simulate an event though.

I finally found the solution to this problem (getting [object Object] as the value) that @mghazanfar and I were having, in the comments on #226: @NevenLiang had a good example of an adapter component that adapts between the API of TextField and the API required by PhoneInput’s inputComponent, which solves this and a few other issues (like the need to implement input.focus)

I’ve created a sandbox demo here: https://codesandbox.io/s/integrate-react-phone-number-input-with-material-uicore-ohfwp

The next major pain point with using material-ui is that there doesn’t appear to be a way to pass props down to the input component. I’m suggesting we add one in issue #280.


Inspect the [object Object] and see what it is.

It’s a string. Something is coercing the Event object into the string, "[object Object]".

Read more comments on GitHub >

github_iconTop Results From Across the Web

OutlinedInput API - Material UI - MUI
API reference docs for the React OutlinedInput component. ... If true , the input element is focused during the first mount. classes, object....
Read more >
React Text Field component - Material UI - MUI
The TextField wrapper component is a complete form control including a label, input, and help text. It comes with three variants: outlined (default), ......
Read more >
FormControl API - Material UI - MUI
API reference docs for the React FormControl component. ... Provides context such as filled/focused/error/required for form inputs. ... classes, object.
Read more >
InputAdornment API - Material UI - MUI
API reference docs for the React InputAdornment component. Learn about the props, CSS, and other APIs of this exported module.
Read more >
Breaking changes in v5, part two: core components - Material UI
This is a reference guide to all of the breaking changes introduced in Material v5, and how to handle them when migrating from...
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