Reputation: 25
I have this function in request.js
import Axios from "axios"
export async function get(res, req, next) {
var resp = await Axios.get("https://api.pro.coinbase.com/products");
let pairs = resp.data.map(a => a.id);
console.log(pairs)
}
in my component I have this :
<script>
import { get } from "../data/request.js";
function getSomething() {
get();
}
</script>
<h1>get something here</h1>
<button on:click={getSomething}>Get !</button>
This way I manage to get the pairs in the console but I use the whole function, how can I use the variable "pairs" on its own in my component ?
Thank you
Upvotes: 1
Views: 322
Reputation: 1635
import Axios from "axios"
export async function get(res, req, next) {
var resp = await Axios.get("https://api.pro.coinbase.com/products");
let pairs = resp.data.map(a => a.id);
console.log(pairs)
return pairs;
}
Add the return keyword
<script>
import { get } from "../data/request.js";
let pairs
function getSomething() {
pairs= get();
console.log(pairs)
}
</script>
<h1>get something here</h1>
<button on:click={getSomething}>Get !</button>
Try this
Upvotes: 1