Download the PHP package mwguerra/wire-bridge without Composer
On this page you can find all versions of the php package mwguerra/wire-bridge. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package wire-bridge
WireBridge
Seamless two-way reactive bridge between Livewire 4 and Vue 3 / React.
State persistence, Filament 5 support, artisan generators, and Vite auto-import included.
Compatible with: Laravel 11 / 12 / 13 · Livewire 4 · Filament 5 · PHP 8.3+
Philosophy
Modern Laravel applications are built on Livewire. It is powerful, productive, and keeps you in PHP. But sometimes you need a rich interactive component — a chart library, a drag-and-drop board, a complex form widget — and the best implementation exists in Vue or React.
The usual answer is "pick one stack." Either go all-in on Livewire + Alpine, or abandon Livewire for Inertia. WireBridge rejects that tradeoff.
The core idea: Livewire owns the page, the routing, the server state, and the lifecycle. Vue or React owns a region of the DOM where rich interactivity lives. The bridge makes Livewire public properties behave like native framework state inside that region — two-way bound, reactive, and persisted — so the JS component feels like it is running in a normal Vue or React application.
You write a normal Vue <script setup> or a normal React function component. The only difference is one import: useLivewire() instead of defining your own state. Everything else — child components, third-party libraries, CSS frameworks, local ref() or useState() — works exactly as it would in a standalone JS app.
The problem it solves
Without WireBridge, embedding Vue or React inside Livewire means:
- Manually passing data through
@json()and data attributes, then parsing them in JS. - Using
wire:ignoreto prevent Livewire from destroying your JS mount, but losing all reactivity between the two worlds. - Writing custom event listeners to push data from JS back to Livewire and vice versa.
- Losing all JS state on every
wire:navigate, parent re-render, or page reload. - Duplicating state management: Livewire properties on the server, a separate store (Pinia, Redux, Zustand) on the client.
WireBridge eliminates all of this. One composable gives you reactive access to every Livewire public property, a way to call any PHP method, and a local state layer that persists across re-mounts — all without writing any glue code.
Features
Two-way reactive data binding
Livewire public properties are automatically synced into your Vue or React component. Change a property in Vue and it pushes to Livewire. Change it in PHP and it appears in Vue. No events, no watchers, no manual synchronization.
Call PHP methods from JS
Any public method on your Livewire component is callable from the JS side via wire. Return values come back as promises.
JS-only local state with persistence
UI concerns like sidebar toggles, form drafts, scroll positions, and active tabs live in local. This state is never sent to PHP but survives page reloads, wire:navigate, and parent Livewire re-renders via sessionStorage.
Automatic state persistence
Both state (Livewire properties) and local (JS-only) are persisted to sessionStorage on every change. When the component re-mounts — after a page reload, wire:navigate, or a parent Livewire re-render — the bridge restores the previous state instantly, before the server round-trip completes.
On the PHP side, #[Session] keeps Livewire properties in the server session as well, giving you double persistence (client + server).
Artisan generators
One command scaffolds the Livewire class, Blade view, and Vue/React component with useLivewire() already wired up.
Vite auto-import
A Vite plugin scans your components directory and auto-registers everything. Drop a new .vue or .jsx file into the folder, and it is immediately available in Blade — no manual registration, no touching app.js.
Filament 5 support
A WireBridgeWidget base class lets you embed Vue or React components inside Filament dashboards, panels, and resource pages with zero Blade files.
Framework-agnostic core
The bridge is three layers: a framework-agnostic core (core.js) that talks to $wire, and thin adapters for Vue (vue.js) and React (react.js). You can mix frameworks on the same page — Vue for the sidebar, React for the main panel — because each mount is independent.
Installation
Step 1: Install the package
Step 2: Run the installer
This publishes the JS bridge files into resources/js/livewire-bridge/, the mount script, example components, and installs the npm dependencies.
Add --no-deps to skip the npm install step if you prefer to manage dependencies yourself.
Step 3: Configure Vite
Add the appropriate framework plugins and (optionally) the auto-import plugin to your vite.config.js:
Step 4: Set up app.js
With auto-import (recommended):
Without auto-import (manual registration):
Quick start
Generate a component
This creates three files:
app/Livewire/TodoList.php — the Livewire component:
resources/views/livewire/todo-list.blade.php — the Blade view:
resources/js/components/TodoList/TodoList.vue — the Vue component:
Add a route and run
Visit http://localhost:8000/todos. The Vue component renders inside the Livewire page. Type in the input — the Livewire $title property updates in real time. Click the buttons — one mutates state client-side, the other calls PHP. Reload the page — everything is restored.
Complete Vue example
A full todo application showing all features: two-way binding, PHP method calls, local state, and CRUD operations.
PHP component
Blade view
Vue component
Notice how the Vue component uses computed, v-model, v-for, scoped event handlers, and conditional rendering — all standard Vue. The only WireBridge-specific code is the useLivewire() import and the wire.method() calls.
Complete React example
The same todo application in React.
PHP component
Use the identical TodoApp.php from the Vue example above. The PHP side is framework-agnostic.
React component
The React component uses useMemo, useState, useEffect, conditional rendering, and .map() — all standard React patterns. The only WireBridge-specific code is useLivewire() and wire.method() / set() / setLocal().
Vue vs React — API comparison
The hook signature and behavior are intentionally parallel. The only real difference is Vue's mutable reactivity (state.x = y) versus React's immutable convention (set('x', y)).
| Concern | Vue | React |
|---|---|---|
| Import | from '../../livewire-bridge/vue' |
from '../../livewire-bridge/react' |
| Hook | useLivewire() |
useLivewire() |
| Read Livewire state | state.count |
state.count |
| Write Livewire state | state.count = 5 |
set('count', 5) |
| Read local state | local.draft |
local.draft |
| Write local state | local.draft = 'hi' |
setLocal('draft', 'hi') |
| Two-way input binding | v-model="state.title" |
value={state.title} onChange={e => set('title', e.target.value)} |
| Call PHP method | wire.save() |
wire.save() |
| Call with args | wire.addItem('x') |
wire.addItem('x') |
| Await return value | wire.compute(5).then(r => ...) |
wire.compute(5).then(r => ...) |
| Local component state | ref(), reactive(), computed() |
useState(), useMemo() |
| Clear persistence | clearPersisted() |
clearPersisted() |
Artisan commands
wire-bridge:install
Publishes JS bridge files, mount script, config, and example components. Optionally installs npm dependencies.
make:wire-bridge
Scaffolds a complete WireBridge component: PHP class, Blade view, and JS component.
Generated files for make:wire-bridge ChatApp --vue:
| File | Purpose |
|---|---|
app/Livewire/ChatApp.php |
Livewire component with #[Session] properties |
resources/views/livewire/chat-app.blade.php |
Blade with wire:ignore + mount partial |
resources/js/components/ChatApp/ChatApp.vue |
Vue SFC with useLivewire() |
For --filament, the PHP class extends WireBridgeWidget and goes into app/Filament/Widgets/. No Blade file is generated because the base class provides it.
Vite auto-import
The Vite plugin eliminates manual component registration. It scans directories for .vue, .jsx, and .tsx files and generates a virtual module that registers them all.
Setup
Naming convention
Component names are derived from file paths using kebab-case:
| File path | Registered name | Blade usage |
|---|---|---|
components/ChatApp/ChatApp.vue |
chat-app |
['component' => 'chat-app'] |
components/Dashboard.jsx |
dashboard |
['component' => 'dashboard'] |
components/Admin/Revenue.vue |
admin-revenue |
['component' => 'admin-revenue'] |
components/Charts/LineChart.tsx |
charts-line-chart |
['component' => 'charts-line-chart'] |
When a file is inside a directory with the same name (e.g., ChatApp/ChatApp.vue), the duplicate is collapsed to just chat-app.
Options
Hot reload
During development, the plugin watches the component directories. When you add or remove a .vue/.jsx/.tsx file, Vite triggers a full reload so the new component is immediately available — no restart needed.
Filament 5 support
WireBridge integrates with Filament dashboards, panels, and resource pages. There are three ways to use it.
Option A: WireBridgeWidget base class (recommended)
Extend WireBridgeWidget instead of Filament\Widgets\Widget. The base class provides the Blade view automatically — you only write PHP and JS.
Then create the Vue/React component as usual:
Option B: Artisan generator
Generates app/Filament/Widgets/RevenueChart.php extending WireBridgeWidget and the Vue component. No Blade file needed.
Option C: Manual integration
Add wire:ignore and the mount partial to any existing Filament widget Blade view:
State persistence
WireBridge persists state at two layers to ensure nothing is lost during re-mounts.
Livewire properties (state)
Persisted both server-side (via Livewire's #[Session] attribute) and client-side (via sessionStorage). The client-side cache provides instant restoration before the server round-trip completes. The #[Session] attribute is optional but recommended for properties that should survive full page reloads.
JS-only state (local)
Persisted only client-side in sessionStorage. Never sent to PHP. Use for UI concerns: form drafts, sidebar toggles, scroll positions, active tabs, accordion states.
Persistence behavior by scenario
| Scenario | state (Livewire) |
local (JS-only) |
|---|---|---|
| Livewire server round-trip | ✅ Kept (snapshot) | ✅ Kept (in-memory) |
| Parent Livewire re-render | ✅ Restored from session | ✅ Restored from sessionStorage |
wire:navigate |
✅ Restored | ✅ Restored |
| Full page reload (F5) | ✅ Restored | ✅ Restored |
| New browser tab | ❌ Fresh start | ❌ Fresh start |
| Tab closed and reopened | ❌ Fresh start | ❌ Fresh start |
Disabling persistence
Per-component in Blade:
At registration time:
Globally in config:
Clearing persisted state
From within a Vue or React component:
Multiple components on one page
Mount different Vue/React components on separate wire:ignore containers within the same Livewire component:
Both components share the same Livewire $wire proxy, so they see the same server state and can call the same PHP methods. You can even mix frameworks — Vue for the sidebar, React for the main panel.
Configuration
Publish the config file:
Architecture
Three-layer design
| Layer | File | Role |
|---|---|---|
| Core | core.js |
Framework-agnostic. Discovers Livewire properties via $wire.__instance(), syncs via $wire.$watch and $wire.$set, manages sessionStorage persistence. |
| Adapter | vue.js / react.js |
Thin wrappers. Vue uses reactive() + watch() + provide/inject. React uses useSyncExternalStore + context. Both expose useLivewire(). |
| Mount | livewire-mount.js |
Listens for wirebridge:mount events from Blade, looks up the registered component, mounts the correct framework. |
Data flow
| Direction | Mechanism | When |
|---|---|---|
| Livewire → JS | $wire.$watch(key, callback) |
After any server round-trip that changes the property |
| JS → Livewire | $wire.$set(key, value) |
When you mutate state.* (Vue) or call set() (React) |
| JS → PHP method | wire.methodName(args) |
On demand (button click, form submit, etc.) |
| Persist (client) | sessionStorage.setItem() |
On every state or local change |
| Persist (server) | #[Session] attribute |
Managed by Livewire automatically |
| Restore (client) | sessionStorage.getItem() |
On component mount, before server round-trip |
API reference
Vue — useLivewire()
| Property | Type | Description |
|---|---|---|
state |
Reactive<object> |
Livewire public properties. Read and write directly. Changes sync to PHP and are persisted. |
local |
Reactive<object> |
JS-only state. Read and write directly. Persisted to sessionStorage, never sent to PHP. |
wire |
$wire proxy |
Raw Livewire proxy. Call any public PHP method: wire.save(), wire.delete(id). Returns promises. |
clearPersisted |
() => void |
Removes all persisted state for this component from sessionStorage. |
React — useLivewire()
| Property | Type | Description |
|---|---|---|
state |
object |
Livewire public properties. Read-only snapshot (immutable React convention). |
local |
object |
JS-only state. Read-only snapshot. |
wire |
$wire proxy |
Raw Livewire proxy. Call any public PHP method. Returns promises. |
set |
(key: string, value: any) => void |
Write a Livewire property. Syncs to PHP and triggers React re-render. |
setLocal |
(key: string, value: any) => void |
Write a JS-only local property. Persisted, triggers re-render. |
clearPersisted |
() => void |
Removes all persisted state for this component from sessionStorage. |
Blade mount partial
WireBridgeWidget (Filament)
Vite plugin
Published file structure
After php artisan wire-bridge:install:
These files are published into your project and have no runtime dependency on the Composer package. You can edit them freely.
Troubleshooting
Component not mounting: Make sure the registered component name in app.js (or the auto-import derived name) matches the component value in your Blade @include('wire-bridge::mount', ['component' => 'name']).
State not syncing: Verify your Livewire properties are public. Private and protected properties are not exposed to $wire.
State lost on reload: Add #[Session] to your Livewire properties for server-side persistence. The client-side sessionStorage cache restores state instantly, but #[Session] ensures the server also remembers.
Vue/React not rendering: Check that wire:ignore is on the mount container element. Without it, Livewire's DOM morphing will destroy the JS app on every server round-trip.
Vite auto-import not finding components: Ensure the component file is inside the configured dirs (default: resources/js/components/) and has a .vue, .jsx, or .tsx extension. Files starting with _ or named index are skipped.
Acknowledgments
WireBridge was inspired by Mingle by Patricio.
License
MIT — see LICENSE for details.
All versions of wire-bridge with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
livewire/livewire Version ^4.0