This client is primarily designed for browser environments. For server-side integrations, use @constructor-io/constructorio-node instead.
DOM-Less Environment
React Native applications don’t have access to standard browser APIs likedocument, window, or native fetch. The Constructor.io client needs these APIs to function properly.
Required Polyfills
To use the client in React Native, you need to provide polyfills for missing browser APIs:1. Fetch API
The client requires a fetch implementation. React Native includes a native fetch, but you need to ensure it’s available globally:2. URL Polyfill
You need a URL polyfill for URL parsing:3. EventTarget Polyfill
For custom event dispatching:Installation
Basic Usage
After setting up polyfills, use the client as you would in a browser environment:Complete Example
Here’s a complete React Native component using Constructor.io:Autocomplete Example
Implementing autocomplete with debouncing:Limitations
- Custom Events: The client dispatches custom events on
window, but these may not work as expected in React Native. Consider using callbacks or state management instead. - EventSource/SSE: The Agent module uses EventSource for Server-Sent Events, which may require additional polyfills or may not work at all in React Native.
- Browser Headers: Some HTTP headers normally populated by browsers (
User-Agent,Referer) may not be available or may need manual configuration.
Best Practices
Initialize Once
Create a single instance of the Constructor.io client and reuse it throughout your app:
Implement Debouncing
Use debouncing for autocomplete and search-as-you-type features to reduce API calls.