Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 🙂

>Solution :

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) } )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading