Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

250
Visualizações
How to save response data in a variable or state in js

i'm trying to use trello-web in react. in the docs it say:

When you have a token, you can do .get, .put, .post and .del, for example:

trello.get('/1/boards').then(console.log)

and everything works fine (with console.log).

But if i want save the response in a variable what i have to change in this line of code to use it in my component?

I dont understand that

.then(console.log) 

print in my console and so i cant save it to reuse correctly. If someone help me to understand.. thanks very much :)

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

.then(console.log) is a shorthand of .then(event => console.log(event)) (or rather, data). You can write your own function that takes that event as an argument, then do whatever you want with it, for example:

.then(save)

function save(event) {
    //do stuff with the event
}

I know you said React, but this should get you going.

about 4 years ago · Juan Pablo Isaza Relatório

0

If u are using react u can make a state in component eg.

[myData, setMyData] = useState();

Now you can handle incoming data by trello.get('/1/boards') returns you a "Promise", you can handle it in two ways

1.

var data = async trello.get('/1/boards')
setMyData(data)
trello.get('/1/boards').then( (data) => { setMyData(data) } )
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda