Correct error in react setState( BinanceAPI .data)
$10-30 USD
Închis
Data postării: aproape 4 ani în urmă
$10-30 USD
Plata la predare
Hi, can anyone help me with this code in react? I'm trying setState based on Binance API
It returns error...
"error"
"Unhandled Rejection (Error): ws does not work in the browser. Browser clients must use the native WebSocket object"
this is my code
```
import React, { useState, useEffect } from 'react'
// Node Binance API
// [login to view URL]
const Binance = require('node-binance-api')
const binance = new Binance().options({
APIKEY: 'xxxxxxxxxx',
APISECRET: 'xxxxxxxxxx'
})
// BTCUSDT - price
const BtcPriceTicker = () => {
const [btcPriceTicker, setBtcPriceTicker] = useState([])
useEffect(() => {
async function fetchMyAPI() {
let response = await [login to view URL]( 'BTCUSDT' )
response = [login to view URL]
setBtcPriceTicker(response)
//[login to view URL](response)
}
fetchMyAPI()
}, [btcPriceTicker])
return <div>{btcPriceTicker}</div>
}
export default BtcPriceTicker;
// error
// Unhandled Rejection (Error): ws does not work in the browser.
// Browser clients must use the native WebSocket object
```
[login to view URL]
using Node Binance API
[login to view URL]
First of all you are calling setbtc... state updater in useeffect and set its value as condition for useeffect call which will keep re rendering the component again and again