Docs
Saving data

Saving data on Gaia

This content is coming soon :~) If you would like this topic prioritized, please create an issue on GitHub!

To save data with Gaia, @micro-stacks/react exports a helpful hook usePutFile that wraps the library react-async-hook. This hook handles asynchronously encrypting and uploading data to the default Gaia hub.

Example

import { usePutFile } from '@micro-stacks/react';
import * as React from 'react';
 
const filename = 'hello-world';
const contents = {
  foo: 'bar',
};
 
const MyGaiaComponent = () => {
  const [gaiaUrl, setGaiaUrl] = React.useState(null as null | string);
 
  const { isLoading, error, hasError, data, putFile } = usePutFile(`${filename}.json`, contents, {
    onSuccess: url => setGaiaUrl(url),
  });
 
  return (
    <div>
      {isLoading && <div>loading...</div>}
      {hasError && <div>{error}</div>}
      {data || gaiaUrl ? <div>file path: {data || gaiaUrl}</div> : null}
      <button onClick={() => putFile()}>save file</button>
    </div>
  );
};