When I subscribe to realtime events in my React Native application. I get the error below.
ERROR Error: URLSearchParams.set is not implemented, js engine: hermes.
appwriteClient
.subscribe(
`databases.${APPWRITE_DATABASE_ID}.collections.${APPWRITE_OPPORTUNITIES_COLLECTION_ID}.documents`,
(response: any) => {
if (response.events.includes(
'databases.*.collections.*.documents.*.create'
)) {
setOpportunities((prevOpportunities: any[]) => {
const updatedOpportunity = [...prevOpportunities, ...response.payload];
return updatedOpportunity;
})
} else if (response.events.includes(
'database.*.collections.*.documents.delete'
)) {
setOpportunities((prevOpportunities: any[]) => {
return prevOpportunities.filter((opportunity) => {
return opportunity.$id !== response.payload.$id
})
})
}
})
I want to listen to the changes in the opportunity collection so that when changes reflect update, create, I immediately update my state.
How best can I handle appwrite event subscription in order to overcome the URLSearchParams error.
Sometimes React Native doesn't include some things that's usually in a regular web context. The usual solution is to add a polyfill. Perhaps you can use
core-js
as mentioned here.Another suggestion is to try
react-native-url-polyfill
, importing it at the root of your React Native project: