Skip to content

Provide a way to find Components from children #2519

@mhamri

Description

@mhamri

I expected something like this

import { children, createMemo } from 'solid-js';

function ParentComponent(props) {
  const c = children(() => props.children);
  
  // Find a specific component by type
  const specificChild = createMemo(() => {
    return c().find(child => child.type === SpecificComponent);
  });
  
  return (
    <div>
      {c()}
      {specificChild({...specificChild.props, item:1})}
    </div>
  );
}

but going up and down the internet couldn't find anything. This is very useful to be able to implement strategy pattern. Also I saw that Angular recently provided some helper functions to get info about a component or update its input.

this could help to generate different structure based on available children

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