It looks like you are using the REST API. The “other” code you are citing is for Scripting app. The REST API and Scripting work differently, and you cannot use the same code in both.
Getting the total number of of records in a table via the REST API is problematic because if you use only the REST API, you must request all of the records to get a count, and you are limited to requesting 100 records at a time with a rate limit of 5 requests per second.
There are several other techniques to get the number of records, using different combinations of scripting, automations, and base design.
A script automation using the SDK is able to determine the number of records with precision in fewer than 100ms. It also has the capacity to call out to a webhook service to report the count. Lastly, script automations can be triggered by the addition or deletion of records in the table, thus making it possible to report the latest count in real-time and only when the count changes.
I typically use this approach and avoid the API for the reasons @kuovonne cited.
Since your react app won’t be able to receive a webhook, your options are limited. You can use a two phase approach. Have your react app call an Airtable webhook automation that triggers an action script. Have that action script calculate the number of records and write the result to a table/record. Have your react app wait for the automation script to run, and then read the result from the table.
This can be a bit klunky, and you may need to make adjustments to ensure that you get the value after the automation runs, as automation runs are not instant. For example, you could timestamp record holding the count, and then your react app can decide if the value is recent enough.
You may also have issues if you have many people using this app. You could exceed the number of automation runs per month.