Skip to content

Small Provider for making it easier to share an baqend db instance between multiple components

Notifications You must be signed in to change notification settings

Baqend/react-baqend-provider

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-baqend-provider

Installation

npm install react-baqend-provider

Wrap your main component

import { db } from 'baqend/realtime'
import { BaqendProvider } from 'react-baqend-provider'

class App extends Component {
  render() {
    return (
      <BaqendProvider db={db.connect('codetalks17', true)}>
        <YourAppContainer />
      </BaqendProvider>
    );
  }
}

Get db connection instance from higher order component

import { baqend } from 'react-baqend-provider'

class YourComponent extends Component {
  constructor(props) {
    super(props)
    this.state = {
      items: []
    }
  }

  componentDidMount() {
    const { db } = this.props
    db.Item.find().resultList().then(items => this.setState({ items }))
  }

  render() {
    return (
      <YourComponent items={this.state.items} />
    )
  }
}

export default baqend(YourComponent);

About

Small Provider for making it easier to share an baqend db instance between multiple components

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published