rsnext/examples/with-stomp/useClient.js
Ali eslamifard 40c6ec4fb0 This example shows how to use STOMP inside a Next.js application. (#8511)
* 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
2019-09-02 19:59:29 -05:00

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