@Riley132
You don't have to worry about page refreshes, Livewire does everything using XHR requests, so there won't be any page refreshes anyway.
I don't know what your views looks like, but if it's a simple project a single component will do the job actually, where you can have two methods to create and fetch the items, and every time an item is created, Livewire with automatically re-execute the render method, therefore it will fetch the latest records.
If you still want to have two components, you will need a way so they can talk right? you have to use "events" and "listeners", so you code becomes like this
public $name; // define this property you want to bind to the input
public function store()
{
// Made it a bit shorter
Item::create(['name ' => $this->name]);
$this->emit('itemAdded'); // creating an event to alert the other component
}
And fetch the items again
class ItemList extends Component
{
protected $listeners = ['itemAdded' => '$refresh']; // handling that event, by re-rendering the component
public $items = [];
/**
* Renders the component
*/
public function render()
{
$this->items = $this->getItemList();
return view('livewire.item-list', $this->items);
}
/**
* Returns a list of items.
*/
public function getItemList()
{
return DB::table('items')->get();
}
}
Hopefully this made the idea clear
Read more about event and listeners here