Skip to content

Can we have a level in the children? #54

@SvenDowideit

Description

@SvenDowideit

I just wanted to do some conditional rendering of the child based on the heading level, and was surprised there wasn't some magic for me - so I used a State

I wonder if there's a better way, or if not, that it might be documented for future users :)

  const [levelNumber, setLevelNumber] = useState(1);

return (
      <Section
        component={
          <H
            render={({ level, Component }) => (
              setLevelNumber(level), (<Component className={`font-bold ${headingLevelClasses[level]} ${className}`}>{heading}</Component>)
            )}
          />
        }
      >
        {levelNumber == 1 && (
          <div>
            <HelpLink className="mr-2" helpUrl={helpUrl} />
          </div>
        )}
        <div className="col-span-2">{children}</div>
      </Section>
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions