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.

[bug][16.5.0] option returns [object Object] instead of string

See original GitHub issue

What is the current behavior? <option> returns [object Object] instead string

Demo: https://codesandbox.io/s/ww5mv2w957

What is the expected behavior? Expected string

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:10
  • Comments:29 (13 by maintainers)

github_iconTop GitHub Comments

10reactions
gaearoncommented, Sep 7, 2018

Since we warned about this before (in 15), and it crashes in unexpected ways, I think the new behavior is actually a bugfix — both for the missing warning, and for inconsistent behavior. It’s very unfortunate that the warnings didn’t get emitted in some cases (to be clear, it did for components returning DOM nodes — but we missed the case for strings). But I think allowing crashes in this case is worse than addressing the problem head on.

The intended workaround if you’re using react-intl is indeed this: https://codesandbox.io/s/6yr4xy5ll3

If you use something else, just make what you’re passing to <option> as a child is actually a string: https://codesandbox.io/s/oom712ov79

Both of these cases don’t crash on updates, and work correctly. Again, very sorry we only discovered this now.

6reactions
Slaterycommented, Jun 19, 2019

If anyone still needs an answer to the original question, as mentioned in earlier comments and in the documentation here, you cannot use a formatted message in the format of

<select>
    <option value="foo">
        <FormattedMessage id="bar"/>
    </option>
</select>

instead I’ve found formating it as such does work:

<select>
    <FormattedMessage id="bar">
        {txt => <option value="foo">{txt}</option>}
    </FormattedMessage>
</select>

where txt will return the id’s default string for whichever Message Descriptor file is selected

Read more comments on GitHub >

github_iconTop Results From Across the Web

node js function return [object Object] instead of a string value
i am quiet new to java script and node js, i am trying to get a value from a MySQL DB, and the...
Read more >
How to set selected option dynamically in Angular 6 - Medium
Selects in Forms are great when you have multiple options. In Angular as a OPTION value we can use not only string literals,...
Read more >
Bug listing with status RESOLVED with resolution FIXED as at ...
... Bug:3 - "poedit-1.1.5.ebuild" status:RESOLVED resolution:FIXED severity:normal ... Bug:3549 - "(b)xforms fails to compile a _working_ shared object.
Read more >
why it is showing [object object] : r/learnjavascript - Reddit
I think you need to convert the object back to a string first in order to display it. I think instead of setting...
Read more >
AURORA: Statistical Crash Analysis for Automated Root ...
the point the program crashes; instead, it might be far earlier ... (which now actually results in a String object) and passed to....
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 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