Whenever I click the button to call sync I get: Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
Any ideas?
import { synchronize } from '@nozbe/watermelondb/sync';
import { database } from '../../index';
const SYNC_API_URL = 'https://example.com/sync';
export async function sync() {
await synchronize({
database,
pullChanges: async ({lastPulledAt}) => {
const response = await fetch(SYNC_API_URL, {
method: 'GET',
headers: {'Authorization': 'Bearer' + $(user.token)},
body: JSON.stringify({lastPulledAt}),
});
if (!response.ok) {
throw new Error(await response.text());
}
const {changes, timestamp} = await response.json();
return {changes, timestamp};
},
pushChanges: async ({changes, lastPulledAt}) => {
const response = await fetch(
`${SYNC_API_URL}?lastPulledAt=${lastPulledAt}`,
{
method: 'POST',
headers: {'Authorization': 'Bearer' + $(user.token)},
body: JSON.stringify(changes),
},
);
if (!response.ok) {
throw new Error(await response.text());
}
},
});
}