Skip to content

Custom Component

safwan39 edited this page Apr 27, 2021 · 5 revisions

to create a custom component you only need to extends Component class

namespace React\Tag;
use React\Component;

class CustomComponent extends Component{
   function render(){
      return new div('I am custom component');
   }
}

it is also allowed to have multiple component returned

class CustomComponent extends Component{
   function render(){
      //here can access children and props
      return [
        new div('first component', $this->props), //pass props to this div
        new div($this->children), //pass children to this div
      ];
   }
}

to render a component

echo new CustomComponent;

echo new CustomComponent(new div('hello'), ['style'=> 'background:red']); //or with children and props
Clone this wiki locally