Skip to content

Rendering elements inside dynamic parent without child remounting #10516

Closed
@0x2E757

Description

@0x2E757

Is it possible to change element's parent so element will be just "moved" from current parent to new?

@StoreConnect("params")
class ParentRenderer extends React.Component<any, any> {
    public render(): any {
        const { children, params: { parent } } = this.props;
        if (parent) 
            return React.createElement(parent, undefined, children);
        }
        return children;
    }
}

Using this code, when ParentRenderer's children is changed the parent is not re-rendered. This is perfect. But if we change parent (actually it is being changed by new children, because each children's componentWillMount is updating store and sets required parent) will happen:

  1. old children unmounting, new children mounting
  2. old parent unmounting, current children unmounting
  3. new parent mounting, current children mounting

The simplest way to solve this (and the only I see) — change children and parent in the same time. But I would like to know is there any other options, because changing children and parent in the same time is breaking my app, and also there is lack of information in the internet about this or similar cases (or my googling skills are broken).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions