1.1.1 • Published 5 years ago

react-gun v1.1.1

Weekly downloads
3
License
MIT
Repository
-
Last release
5 years ago

Notice

This repository is unmaintained due to my lack of time and due to not keeping up with Gun or using it in any of my projects.

React Gun

Simple Higher-Order Component for GunDB in React

Installation

Install with yarn or npm

yarn add react-gun

Initialize GunProvider to make your Gun() object available to any component...

App.js

import React, { Component } from 'react';
import Gun from 'gun';
import { GunProvider } from 'react-gun';

const App = props => {
  // Initialize all your app stuff
  let gun = Gun();
  return (
    <GunProvider gun={gun}>
      <ComponentThatUsesGun />
    </GunProvider>
  );
};
export default App;

Then call your gun instance by wrapping your component with {withGun}like so

Component.js

import React, { Component } from 'react';
import { withGun } from 'react-gun';

class ComponentThatUsesGun extends Component {
  state = {
    foo: null,
  };
  componentDidMount() {
    // Get objects from Gun() instance and use it to update state or do whatever else you'd like with it
    this.props.gun.get('foo').on(bar => {
      this.setState({
        foo: bar,
      });
    });
  }
  render() {
    if (!this.state.foo) {
      return <div>Loading...</div>;
    }
    return <div>{this.state.foo}</div>;
  }
}

export default withGun(ComponentThatUsesGun);
1.1.1

5 years ago

1.1.0

5 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago