TanStackT
TanStack2y ago
4 replies
popular-magenta

Error: Rendered more hooks than during the previous render.

function useIndicator() {
const params = useParams<{token: string, chart: string}>()
const {data} = useQuery({
queryKey: ['indicator'],
queryFn: async () => {
const res = await fetch("http://localhost:3000/api/assets/" + params.token)
const data = await res.json() as AssetsModel[]

const ind = data.map((i) => i.categories.map((c) => c.subcategories.map((w) => w.indicators.find((ind => ind.short_name === params.chart)))))[0][0]

return ind[0]
}
})
return data
}
function usePrice() {
const {data} = useQuery({
queryKey: ['price'],
queryFn: async () => {
const res = await fetch("http://localhost:3000/api/price?symbol=BTCUSDT&r=1d")
const data = await res.json()

return data
}
})
return data
}

export function createChartFactory(urlSearchParams: URLSearchParams) {
const indicator = useIndicator()

if(!indicator) return null

const price = usePrice()

return {
indicator,
price
}
}
Captura_de_Tela_2024-04-20_as_16.03.01.png
Was this page helpful?