API Call

In Sinux is easy to create a command that call a store then save the result in a store.

import { Store } from 'sinux';

const apiStore = new Store({},'get');
apiStore.get.add(async function (state, url) {
    try{
      const { status } = await fetch(url);
      return { status };
    } catch (e) {
      console.log(e)
      throw new Error(`error in getting ${url}`);
    }
});

apiStore.get('http://google.com').then(console.log, console.log);

results matching ""

    No results matching ""