wavesoft / dot-dom

.dom is a tiny (512 byte) template engine that uses virtual DOM and some of react principles
Apache License 2.0
809 stars 53 forks source link

Children inside functional components #40

Closed caracal7 closed 5 years ago

caracal7 commented 6 years ago

How to use children inside custom components? Something something like

H( MyComponent, {prop: "value"}, H( 'child' ), MySubComponent) & etc.

rjoydip-zz commented 5 years ago

@caracal7 If you want to say render child component from parent component then here it is.

const { div, span, h3 } = H;
const appDiv = document.body;

const HeadingComponent = () => {
  return div(
    h3('.dom render child inside parent component'),
    H(
      MainComponent, { value: 'M' },
    )
  );
}

const SubComponent = (props, state, setState) => {
  return div('Sub component props: ', span(`${props.value}`));
}

const MainComponent = (props, state, setState) => {
  return div(
    'Main component props: ', span(`${props.value}`),
    H(
      SubComponent, { value: 'S' }
    )
  );
}

R(
  H(
    HeadingComponent
  ),
  appDiv
)

I hope you wanted this.

wavesoft commented 5 years ago

@rjoydip thanks for handling this 👍 @caracal7 I am going to close this, open it again if you still have issues.