Installation:
composer require ethanbarlo/livewiremesh
Publish the config (if needed):
php artisan vendor:publish --provider="EthanBarlo\LivewireMesh\LivewireMeshServiceProvider"
First Use Case: Add the package to a Livewire component:
use EthanBarlo\LivewireMesh\LivewireMesh;
public function mount()
{
LivewireMesh::mount('MyReactComponent', [
'prop1' => $this->someProperty,
'prop2' => $this->anotherProperty,
]);
}
Blade Integration:
@livewireMesh('MyReactComponent', [
'prop1' => $this->someProperty,
'prop2' => $this->anotherProperty,
])
README.md for basic examples and API reference.config/livewiremesh.php for package settings (e.g., React build paths, debug mode).EthanBarlo\LivewireMesh\LivewireMeshServiceProvider for bootstrapping logic.Component Mounting:
LivewireMesh::mount() in Livewire component methods (e.g., mount(), updatedProperty()).LivewireMesh::mount('Counter', ['count' => $this->count]);
Reactive Updates:
updated* hooks:
public function updatedCount()
{
$this->emitToMesh('Counter', 'updateCount', $this->count);
}
Event Handling:
public function handleReactEvent($eventName, $payload)
{
// Process payload (e.g., update Livewire state)
}
// In your React component
this.$emit('reactEvent', { data: 'payload' });
Conditional Rendering:
shouldRender() to control when React components mount:
public function shouldRender()
{
return $this->isReadyToRender;
}
Build Process:
config/livewiremesh.php to point to your React build output (e.g., public/build/react).TypeScript Support:
declare module '@livewiremesh/react' {
interface LivewireMeshProps {
count: number;
}
interface LivewireMeshEvents {
updateCount: (count: number) => void;
}
}
Testing:
LivewireMesh in PHPUnit:
$this->partialMock(LivewireMesh::class, function ($mock) {
$mock->shouldReceive('mount')->once();
});
Prop Reactivity:
LivewireMesh::reactive() to mark specific props:
LivewireMesh::reactive(['nested' => $this->nestedObject]);
Event Naming Collisions:
react_):
this.$emit('react_submitForm', { data });
Build Paths:
react_build_path in config may break asset loading.public/dist/react).Debugging:
'debug' => env('APP_DEBUG', false),
Performance:
LivewireMesh::lazy() to defer mounting until needed:
LivewireMesh::lazy('HeavyComponent', ['data' => $this->data]);
State Management:
public $globalConfig = ['theme' => 'dark'];
// Accessible in React via `this.$wire.globalConfig`.
Custom Hooks:
LivewireMesh::hook('mount', function ($component, $props) {
if (!$this->auth->check()) {
return false; // Skip mounting
}
return $props;
});
Fallbacks:
@livewireMesh('MyComponent', [], fallback: '<p>React not supported</p>')
Versioning:
composer.json to avoid breaking changes during early adoption:
"ethanbarlo/livewiremesh": "1.0.0"
How can I help you explore Laravel packages today?