Issue accessing component variable

Hello,
I am struggling with a component, if anyone has an idea I would be glad to hear it.
Basically, I have a front end form that allows users to query an external API. I want to store the query result in a class variable in order to be accessed later on in another form.
I can query and display the query result in my view but when launching the onSelect function $this->searchResults is empty and actually even page[‘searchResults’] is empty even if it was previously set.
Thank you for your help

namespace Your\Plugin\Components;

use Cms\Classes\ComponentBase;
use Illuminate\Support\Facades\Http;

class CompanySearch extends ComponentBase
{
    public $searchResults = [];

    public function componentDetails()
    {
        return [
            'name' => 'Company Search',
            'description' => 'Search for companies and prefill form with details'
        ];
    }

    public function onRun()
    {
        // Initialize the search results
        $this->page['searchResults'] = $this->searchResults;
    }

    public function onSearch()
    {
        $query = post('query');

        $response = Http::get('https://recherche-entreprises.api.gouv.fr/search', [
            'q' => $query
        ]);

        if ($response->successful()) {
            $this->searchResults = $response->json();
        } else {
            $this->searchResults = [];
        }

        // Store search results
        $this->page['searchResults'] = $this->searchResults;
    }

    public function onSelect()
    {
        // Access the search results
        $searchResultsbis = $this->searchResults;
        $this->page['searchResultsbis'] = $this->searchResults;
        ];
    }
}

I managed to do it with session but it does not seem to be the best way to achieve this.
Let me know if there is a better solution.

use Session;
public $searchResults = [];
onrun: $this->page['searchResults'] = Session::get('searchResults', []);
onsearch: $searchResults = Session::get('searchResults', []);

Hey @youp

You got it, except you may want to use Cache for the results and Session for the query… something like this

public function onRun()
{
    $this->page['searchResults'] = $this->fetchSearchResultsCached();
}

public function onSearch()
{
    $this->page['searchResults'] = $this->fetchSearchResultsCached();
}

protected function fetchSearchResultsCached() 
{
    $userInput = input('query', \Session::get('component-search-query'));
    if (!$userInput) {
        return [];
    }

    \Session::put('component-search-query', $userInput);

    $cacheKey = 'component-search-'.md5($userInput);
    $expires = \Date::now()->addSeconds(3600);
    return \Cache::remember($cacheKey, $expires, function () {
        $response = Http::get('https://recherche-entreprises.api.gouv.fr/search', [
            'q' => $query
        ]);

        if ($response->successful()) {
            return $response->json();
        } else {
            return [];
        }
    });
}

Thanks a lot for the input