Installation
composer require mwguerra/wire-bridge
npm install @wire-bridge/vue @wire-bridge/react
Add to vite.config.js:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import wireBridge from '@wire-bridge/vite';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
wireBridge(),
],
});
First Use Case: Livewire + Vue Bridge
php artisan make:livewire MyComponent).<script setup>
import { useLivewire } from '@wire-bridge/vue';
const { data, set } = useLivewire('my-component', {
// Initial props
name: 'John Doe',
});
// Two-way binding works automatically
const updateName = () => set({ name: 'Jane Doe' });
</script>
First Use Case: Livewire + React Bridge
import { useLivewire } from '@wire-bridge/react';
function MyComponent() {
const { data, set } = useLivewire('my-component', {
name: 'John Doe',
});
const handleChange = () => {
set({ name: 'Jane Doe' });
};
return <input value={data.name} onChange={handleChange} />;
}
Livewire as State Source
$name, $count) are exposed as data in the JS component.set().<script setup>
const { data } = useLivewire('my-component');
// data.name, data.count are reactive
</script>
Event Handling
const emit = useLivewire('my-component').emit;
emit('customEvent', { payload: 'data' });
public function customEvent($payload) {
$this->dispatch('js-event', payload: $payload);
}
Form Handling
set() for form submissions:
const handleSubmit = () => {
set({ email: 'test@example.com' });
// Livewire will handle validation/processing
};
Filament 5 Support
useLivewire() in Filament panels:
<script setup>
const { data } = useLivewire('filament.resource', {
resource: 'PostResource',
record: 1,
});
</script>
Third-Party Libraries
vue-draggable or react-chartjs-2 work as-is:
<script setup>
import { Draggable } from 'vue-draggable';
const { data } = useLivewire('drag-component');
</script>
<Draggable v-model="data.items" />
Artisan Generators
php artisan wire:make MyComponent --vue --react
Nested State
<script setup>
const { data } = useLivewire('nested-component');
// data.user.profile.name updates Livewire
</script>
Optimistic Updates
const setOptimistic = (key, value) => {
data[key] = value; // JS updates first
set({ [key]: value }); // Sync to Livewire
};
Conditional Binding
v-if/v-show with Livewire data:
<div v-if="data.isActive">Active Content</div>
Initialization Timing
useLivewire() may not be ready on component mount.onMounted or check data for undefined:
onMounted(() => {
if (!data) return;
// Safe to use data here
});
Circular References
JSON.parse(JSON.stringify()) for cleanup.Event Conflicts
@wire:init, @wire:ignore) may conflict with Vue/React lifecycle.@wire:custom-event="handleEvent"
Vite Auto-Import
vite.config.js:
wireBridge({
livewire: ['my-component', 'another-component'],
});
Check Sync State
data changes to verify sync:
watch(data, (newVal) => {
console.log('Livewire data updated:', newVal);
}, { deep: true });
Livewire Logs
config/livewire.php:
'log' => env('LIVEWIRE_LOG', true),
Network Tab
State Persistence
persist: false in useLivewire():
useLivewire('my-component', { persist: false });
Custom Serialization
// In Livewire component
public function serialize($property) {
return match ($property) {
'complexData' => json_encode($this->complexData),
default => parent::serialize($property),
};
}
Vite Build Modes
import.meta.env.MODE for conditional logic.Custom Hooks
useLivewire() with custom logic:
const { data, set, emit } = useLivewire('my-component');
const customHook = (payload) => {
set({ customField: payload });
emit('customEvent', payload);
};
Middleware
useLivewire() calls:
// vite.config.js
wireBridge({
middleware: (wire) => {
wire.data = { ...wire.data, timestamp: Date.now() };
return wire;
},
});
TypeScript Support
interface MyComponentProps {
name: string;
count: number;
}
const { data } = useLivewire<MyComponentProps>('my-component');
How can I help you explore Laravel packages today?