-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
listChildren
array elements have no key
#2
Comments
Works fine for me: import React from 'react';
import { render } from 'ink';
import { Task } from 'ink-task-list';
render(
<Task
label="Label 1"
isExpanded
>
<Task
label="Label 2"
state="loading"
/>
</Task>
); Can you provide reproduction code? |
Yeah, so I was creating children in a separate function (I'm using the expanded area to prompt questions about currently running tasks) and passed it as a prop, which caused it: <Task label="Label 1" isExpanded children={<Text>Label 2</Text>} /> (I used It's a bit odd because both cases, the
(emphasis mine) which suggests (to me) that React is treating This behavior also appears consistent between React 16 + 17. FWIW, if no children are provided and you render the expanded box anyway, does it take up space? Alternatively, might be better to use the |
Using |
This resolves the key issue when `Task` is passed `children` from a parent component. Fixes privatenumber#2.
* Use React.Children.toArray This resolves the key issue when `Task` is passed `children` from a parent component. Fixes #2. * test: cover children prop Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
Thanks for the details and fix. Out of curiosity, what's the reasoning behind passing in children as a prop? |
🎉 This issue has been resolved in version 1.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@privatenumber So I've got an array that's a list of tasks: [{
label: 'A task',
run: async () => { ... do stuff ... }
}] Those tasks will throw errors if they need a prompt (e.g. In render, we tasks.map((task, i) => (
<TaskList>
<Task label={task.label) {...getTaskProps(task, i, state)} />
</TaskList>
return { status: 'loading' / 'success' / etc, isExpanded: true / false, children: null / <ConfirmInput ... /> } That's a long-winded way of saying " Other than this minor issue, the lib has worked great for this use case, btw. Great work, thank you! |
Ahh I see. Thanks for the explanation! |
Bug description
The
Task
component convert its non-array children into an array, but in doing so, doesn't provide akey
to the element within, producing the following error:Reproduction steps
Task
a single element child +isExpanded
.ink
.Environment
The text was updated successfully, but these errors were encountered: