LiveWire hydrate

What seems to be the problem:

hydrate function does not work according to videos

Steps to Reproduce:

just follow the video “lifecycle-hooks”

if you type into the input field the hydrate method doe not work at all

Are you using the latest version of Livewire:

2.3 (yes)

Do you have any screenshots or code examples:

<?php

namespace App\Http\Livewire;

use Illuminate\Http\Request;
use Livewire\Component;

class LifecycleHooks extends Component
{
    public $name = 'Jelly';

    public function mount($name)
    {
        $this->name = $name;
    }

 public function hydrate()
    {
        $this->name = 'teetetetet';
    }

    public function render()
    {
        return view('livewire.lifecycle-hooks');
    }
}

<div>
    <input wire:model="name" type="text">
    TEST {{ $name }}
</div>
1 Like

Hey, @reniar1
Hydrate and dyhadrate it’s just terms not methods

Notice in the above component we are binding directly to the “title” and “content” model attributes. Livewire will take care of hydrating and dehydrating the model between requests with the current, non-persisted data.

See more here:

1 Like

I don’t understand what you are saying, obviously it is a method

And it doesn’t work like documented:

see:

See the comments below the question.

I dont think this is resolved, pointing to other not validated comments is not really helping. @reniar1 you can get it to work when you something other than ‘name’ to see what Hydrate does. Example:

    public $name = 'jelly';
    public $hydrate;

    public function mount($name)
    {
        $this->name = $name;
    }

    public function hydrate()
    {
        $this->hydrate = 'hydrate!';
    }

But something seems to have changed about how Hydrate works, so some insight in this would be appreciated if anyone can.

2 Likes

You can use the following code to test it .

Component.blade.php

<div>

    <label>
        <input wire:model="name" type="text">
    </label>

        <div>
            <span>{{ $name }}</span>
            <hr>
            <span>{{ $triggerValue }}</span>
        </div>
    </div>

Component.php

class ComponentName extends Component
{
    public $name = 'Jelly';
    public $triggerValue = '';

    public function mount( $name){

        $this->name = $name;
    }

    public function hydrate(){
        $this->triggerValue = 'Its Hydrated';
    }
1 Like

I came to this page to find out WHAT is meant by ‘hydrate’. I am mystified by the verb itself as it does not explain what action is being beformed. Could someone use some different verbs to explain the process/method/function/magic that is performed by the act of ‘hydrating’?

I would like to know the state of the data before ‘hydrating’, the state of the data AFTER ‘hydrating’ and,
not only WHEN it is performed but WHY.

As I have found, only someone with an actual deep understanding of the process can explain it in simpler terms so that it is both accurate and clear, even thogh it may use more words. After that we can all use the shortcut term ‘HYDRATE’ as if we know what the heck is going on.

1 Like