Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
In a React Component Class where do you declare a websocket connection?

I'm trying to use a websocket connection in a component class, but I need to declare it seperately from the function that opens it. Is there a way to declare universally or in state so that I can access the open websocket, so that I can close it before opening up another.

I have tried declaring at the top of the page with imports

const ws = new WebSocket("wss://ws-feed.pro.coinbase.com");

Also making it an attribute of the class:

lass App extends Component {
  constructor (props) {
    super(props);
    this.ws = new WebSocket("wss://ws-feed.pro.coinbase.com");
  this.state = {
  
  }
}

but it will always throw the error: 'ws' is not defined no-undef

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!