I am using the Next Js app for Amity integration. I have installed the JS-SDK
npm install @amityco/js-sdk --save.
Whenever I am reloading the page, its giving me an error
:- r [ASCError]: ASCWebSDK: Only one instance of the SDK Web Client can be created.
Here is a sample example of how I am using it.
In pages/ _app.js
const client = new AmityClient({
apiKey: 'API_KEY',
apiRegion: ApiRegion.SG,
});
function MyApp({ Component, pageProps }) {
return (
<ThemeProvider theme={theme}>
<Component {...pageProps} client={client} />
</ThemeProvider>
);
}
It works fine when moving across different pages, but when I reload it gives the error.
:- r [ASCError]: ASCWebSDK: Only one instance of the SDK Web Client can be created.
Inside Components/community.js → useEffect hook ( accepting client as props in community.js )
client.registerSession({
userId: '1234',
displayName: 'TestName',
authToken,
});
const postLiveObject = await PostRepository.postForId(
'1234',
);
await postLiveObject.once('dataUpdated', (model) => {
console.log('Post', model);
});
Its not printing console.log(‘Post’, model);
How to resolve this on the Next Js app.