Skip to content

Commit

Permalink
InteractiveList - legger inn key prop og bruker den hvis finnes (#3464)
Browse files Browse the repository at this point in the history
Unngår spreading av key-prop som gir warning
  • Loading branch information
hallvardastark authored Dec 5, 2024
1 parent 493b8ea commit 9e60836
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import classnames from 'classnames';
import styles from './interactiveList.module.css';
import React from 'react';
import ChevronIconBlack from '../icons/ChevronIconBlack';
import ChevronIconGray from '../icons/ChevronIconGray';
import styles from './interactiveList.module.css';

export interface InteractiveListElement {
content: React.ReactNode;
Expand All @@ -11,7 +11,7 @@ export interface InteractiveListElement {
}

interface InteractiveListProps {
elements: InteractiveListElement[];
elements: Array<InteractiveListElement & { key?: string }>;
}

const InteractiveListElement = (props: InteractiveListElement) => {
Expand All @@ -37,10 +37,10 @@ const InteractiveListElement = (props: InteractiveListElement) => {

const InteractiveList = ({ elements }: InteractiveListProps) => (
<ul className={styles.interactiveList}>
{elements.map(elementProps => (
// eslint-disable-next-line react/jsx-key
<InteractiveListElement {...elementProps} />
))}
{elements.map((elementProps, index) => {
const { key, ...rest } = elementProps;
return <InteractiveListElement key={key ?? index} {...rest} />;
})}
</ul>
);

Expand Down

0 comments on commit 9e60836

Please sign in to comment.