40c6ec4fb0
* This example show how to use STOMP inside a Next.js application. * Fix useEffect * Add _app.js implementation * Fix lint error * Fix lint error * Update examples/with-stomp/README.md Co-Authored-By: Luis Fernando Alvarez D. <luis@zeit.co> * withStomp removed * The url address changed * _app.js removed. useClient added. * remove * revert * Add next.config.js * Updated readme
21 lines
397 B
JavaScript
21 lines
397 B
JavaScript
import React from 'react'
|
|
import { Stomp } from '@stomp/stompjs'
|
|
|
|
let stompClient
|
|
|
|
const useClient = () => {
|
|
const [client, setClient] = React.useState(stompClient)
|
|
|
|
React.useEffect(() => {
|
|
if (!stompClient) {
|
|
stompClient = Stomp.client(process.env.STOMP_SERVER)
|
|
}
|
|
if (!client) {
|
|
setClient(stompClient)
|
|
}
|
|
}, [client])
|
|
|
|
return client
|
|
}
|
|
|
|
export default useClient
|