Common code between Ionic React and PHP

I am working on an Ionic React application and a PHP website. These two projects must share a chat, accessible from both, but not limited to it. I developed the chat in the application as a set of pages of the application.
What is the best way to reuse this code in a more traditional non-Ionic React based web architecture?
I can’t rely on the application built in my Ionic project because it is much more complete than just the chat.
I thought about making the chat a standalone app that I could build and whose built code could be used in my website, but I’m not sure if I can have “an Ionic app within an app” on the mobile side.
Would you have any ideas for my problem?

It sounds like you need an API to share the chat data between the react mobile app and PHP site.

I do use an API for the back, the aim is to share the front if possible

In my case, I have a Drupal 9 website built in PHP, and an Ionic app for iOS and Android.

Originally, I had used the Drupal site for everything, but I built the Ionic app because users kept asking for an app.

As I improved the ionic app, the Ionic app’s features surpassed what was available on my Drupal site in terms of functionality, so at that point, I just added the Ionic app as a PWA on my Drupal server.

So now I use the Ionic app functionality everywhere-- on iOS, Android, and on my Drupal site. And then I am still using the Drupal site for everything not provided in Ionic.

if you only want to use the chat part of the app on your web server, you may be able to create a limited version by gating the non-chat functionality by checking for the platform.

To check if I am running on mobile, I use this code:

export const isPlatformMobile = (): boolean => (isPlatform('capacitor'));

This way, you could just upload the full app to the webserver, but it would disable all the unneeded functionality (after adding the appropriate gates by checking the platform).