I’m building chat app with vite + react and adonis6
I’m so lost with the Doc,
Some one ca help please?
i don’t really want to use another package :’)
thank you
This is my code on the react client side
const { transmit ,api } = useApi();
const subscription = transmit.subscription(`private`);
subscription.create()
// subscription.onMessage((data) => {
// console.log("Nouveau message privé:", data);
// });
.then((data) => {
console.log(data);
})
.catch((err) => {
console.log(err);
})
const sendMessageToApi = () =>{
api.post('/chat/private', { message:'Hello' })
.then((res) => {
console.log(res.data);
})
.catch((err) => {
console.log(err);
})
}
useEffect(() => {
sendMessageToApi()
}, []);
This is my code on Adonis server side
export default class MessagesController {
public async sendMessage({ request }: HttpContext) {
const { message } = request.body()
transmit.broadcast(`private`, { username: 'lanz' })
return 'Message sent'
}
}
New contributor
Tracy Finoana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.