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

0 or other falsy but non-nullish values being ignored for certain key properties #4111

Closed
noinkling opened this issue Nov 15, 2020 · 1 comment · Fixed by #4112
Closed

0 or other falsy but non-nullish values being ignored for certain key properties #4111

noinkling opened this issue Nov 15, 2020 · 1 comment · Fixed by #4112
Labels

Comments

@noinkling
Copy link
Contributor

noinkling commented Nov 15, 2020

Bug Report

Using falsy checks for keys in certain places means we're unable to use 0 (and possibly false, NaN, etc.) as a key. In #1729 the resolution seemed to be to use nullish semantics, but at least a few components didn't get the memo:

const finalKey = childKey || [date, meta, summary].join('-')

key={childKey || result.id || result.title}

const key = item.key || [item.header, item.description].join('-')

I was going to open a PR fixing these cases to use Lodash's isNil() as elsewhere, however I was thinking now that the nullish coalescing operator (??) is part of JS, maybe you guys would like to add the Babel plugin for it so we could use that instead? I notice that the optional chaining plugin is already there.

Edit: I just realized that nullish coalescing is probably already available from preset-env.

Steps

e.g:

const items = [
  { childKey: 0, content: 'Foo' },
  { childKey: 1, content: 'Bar' }
];
<Item.Group items={items} />

Expected Result

The generated Items should have a key of "0" and "1" respectively.

Actual Result

The first item has a generated key based on its other props: "Foo---"

Version

2.0.1

Testcase

Directly from one of the doc examples: https://codesandbox.io/s/tooji?module=/example.js

@noinkling noinkling changed the title Certain key properties ignoring 0 or other falsy but non-nullish values 0 or other falsy but non-nullish values being ignored for certain key properties Nov 15, 2020
@layershifter
Copy link
Member

Was fixed in semantic-ui-react@2.0.3 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants