Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug on onChatStarted and localstorage #25

Open
riandev25 opened this issue Jun 15, 2023 · 0 comments
Open

Bug on onChatStarted and localstorage #25

riandev25 opened this issue Jun 15, 2023 · 0 comments

Comments

@riandev25
Copy link

`import axios from 'axios';
import { useEffect, useRef } from 'react';

const TawkMessengerReact = require('@tawk.to/tawk-messenger-react');

const ChatSupport = () => {

const onPrechatSubmit = async (data: IPreChatDetails[]) => {
try {
const response = await axios.post('/api/sample', data);
const name = response.data.user[0].answer;
const email = response.data.user[1].answer;
localStorage.removeItem('name');
localStorage.removeItem('email');
localStorage.setItem('name', name);
localStorage.setItem('email', email);
console.log('pre submit submitted!');
} catch (err) {
console.error(err);
}
};

const onChatStarted = async () => {
try {
const name = localStorage.getItem('name');
const email = localStorage.getItem('email');
console.log(name);
const response = await axios.post('/api/sample', {
name,
email,
});
console.log('started');
} catch (err) {
console.log(err);
}
};

return (

);
};

export default ChatSupport;
`

When running it on the browser and triggering the onPrechatSubmit and onChatStarted, this is the order on the browser's console:
null --> console.log(name);
pre-chat submitted! --> console.log('pre submit submitted!');
started --> console.log('started');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant