Skip to content
This repository has been archived by the owner on Mar 18, 2023. It is now read-only.

paulkre/php-react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

React for PHP

React-like library for component based development in PHP.

Usage

class MyComponent extends \React\Component {
  static function render($props = []) {
    ?>
    <p>This is the message: <?= $props['msg'] ?></p>
    <?php
  }
}

class MyOtherComponent extends \React\Component {
  static function render($props = []) {
    ?>
    <div>
      <?php self::render_children($props['children']) ?>
    </div>
    <?php
  }
}

// Basic
MyComponent::render(['msg' => 'Hello World!']);

// Nested
MyOtherComponent::render([
  'children' => [
    new MyComponent(['msg' => 'First child']),
    new MyComponent(['msg' => 'Second child']),
  ]
]);

I recommend using webpack so you can co-locate both the back end and the front end code of each component in the same directory. The structure for a generic project could look like this:

.
└── src
    ├── MyComponent
    │   ├── Component.php
    │   ├── index.js
    │   └── style.css
    ├── MyOtherComponent
    │   ├── Component.php
    │   ├── index.js
    │   └── style.css
    └── index.js

About

React-like library for component based development in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages