React Next.js создание компонента принимающего параметры + другие компоненты

Доброго времени суток!

Нужно создать компонент который будет принимать параменты + вложенные элементы html и другие компоненты

Есть компонент:

import { Component } from 'react'
import styled from 'styled-components';

export class ListItem extends Component {
    constructor(props) {
        super(props)
        this.state = {
            id: this.props.id,
            title: this.props.title
        }
    }

    render() {
        const { id, title } = this.state
        console.log(title);
        return (
            <Li key={id}>
                <Span>{title}</Span>
                //<Component {..this.props}/> вызывает ошибку. без этой строки компонент работает но не отображает вложенные компоненты
            </Li>)
    }
}

const Li = styled.li`
    color: rgba(0, 0, 0, 0.87);
    border: none;
    cursor: default;
    height: 32px;
    display: inline-flex;
    outline: 0;
    padding: 0;
    font-size: 0.8125rem;
    box-sizing: border-box;
    transition: background-color 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms,box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
    align-items: center;
    font-family: "Roboto", "Helvetica", "Arial", sans-serif;
    white-space: nowrap;
    border-radius: 16px;
    vertical-align: middle;
    justify-content: center;
    text-decoration: none;
    margin: 2px;
    background-color: #e0e0e0;
    `;
    
const Span = styled.span`
    overflow: hidden;
    white-space: nowrap;
    padding-left: 12px;
    padding-right: 12px;
    text-overflow: ellipsis;
    `;

подключаю компонент так:

import { ListItem } from './UI/li_grey'
...

<ListItem key={i.id} title={i.name}><button className={styles.button_item_admin_menu} onClick={(e) => this.DeleteItemMenu(i.id, e)}>x</button></ListItem>

Буду благодарен за помощь!


Ответы (1 шт):

Автор решения: Артур Франк

Нашел решение... Для передачи дочерних элементов в компонент надо использовать не <Component {..this.props}/> а {children} ( const { children } = this.props;

→ Ссылка