Now that Livewire v3 came about, it looks much better and I had to try it again, to see if I could use it for my future projects. Wire:navigate is so amazing, but I just tested the very thing that made me leave the first time.
If it's a skill issue on my part, well, I'm a fool, will eat my critique and be happy that I was using Livewire wrong and can start using it properly now.
Let me demonstrate:
Model: class File extends Model { protected $appends = ['rand']; protected $fillable = ['name']; public function getRandAttribute() { return rand(1, 100); } }
Livewire Component: class Test extends Component { public $count = 1; // public $files = []; public function mount() { // $this->files = File::all(); } public function do() { $this->count++; } public function render() { return view('livewire.test')->with([ 'files' => File::all(), ]); } }
Livewire Blade: {{ $count }} @foreach ($files as $file) {{ $file->name }} {{ $file->rand }} @endforeach
I tested both commented and `with()` options, but both had same result. On every click, which only increases the count, the `rand` value changed.
Now you might see what's my problem. If the rand attribute was s3 file getter, I'm paying for every rerender.
https://i.redd.it/46gzkg08t5sb1.gif
So, is this doable in Livewire with different approach, or does it have to be like this? submitted by /u/narrei
[link] [comments]
0 comments:
Post a Comment
Thanks