1. Go to this page and download the library: Download phpreact/component library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpreact / component example snippets
namespace React\Tag;
use React\Component;
class CustomComponent extends Component{
function render(){
return new div(['style'=> 'border:1px solid #eee;border-radius:4px;max-width:500px;padding:5px;margin:10px'],[
new p(['style'=> 'color:red;background:blue'], 'Hello World'),
new div('Many div')
]);
}
}
React\Tag::register('tag1');
React\Tag::register(['newtag1', 'newtag2']); //multiple html tags
echo new CustomComponent;
class CustomComponent extends Component{
var $state = ['test' => 1];
function componentDidUpdate($prevState, $currState){} //run only when there's state update
function render(){
$test = $this->state->test;
return new div(['style'=> 'border:1px solid #eee;border-radius:4px;max-width:500px;padding:5px;margin:10px'],[
new p(['style'=> 'color:red;background:blue'], 'Hello World',),
new div('Many div'),
new button(['onclick'=> "this.setState({test: ".($test+1)."})"], "set my state ($test)")
]);
}
}
namespace React\Tag;
use React\Component;
= [], $text){
return new div(['style'=>'display:flex'], array_map(function($v) use($text){
return new Car(['text'=> $v . $text]);
}, $children));
}
function Car($text = ''){
$state = \React\useState(['test'=> 1]);
return new div(['onclick'=> 'this.setState(function(state){ return {test: state.test + 1}})','style'=> [
'color'=> '#fff',
'border-style'=>'solid',
'border-radius'=> 2,
'padding'=>5,
'border-color'=> 'red',
'border-width'=> 2,
'margin' => 5,
'background'=> 'brown',
'width'=> '100%',
'text-align'=> 'center'
]], $text . ' '. $state->test);
}
class App extends Component{
function render(){
return [
new div(['style'=>'color:red'],'test world'),
new div(['style'=>'color:red'], 'cool'),
new Cars(['text'=> ' hello world'],['Volsvagen', 'Kia', 'via']),
];
}
}
echo new App;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.