0.0.282 • Published 2 months ago

@braustin-holdings/homebase-react v0.0.282

Weekly downloads
-
License
ISC
Repository
github
Last release
2 months ago

homebase-react

A React client for the @braustin-holdings/homebase-node-sdk.

This package will obtain a JSONwebtoken from Homebase and provide you a React Context which contains a pre-configured fetch request which you can use to make GraphQL requests to Homebase.

Installation

1) Make sure @braustin-holdings/homebase-node-sdk is installed and configured on your server. 2) npm i @braustin-holdings/homebase-react

Usage

Import the HomeBaseCtxProvider and wrap it around the components that will need access to HB. This may be around your entire app.

1. Wrap your components in the Provider

import { HomebaseProvider } from '@braustin-holdings/homebase-react';
 
const App = () => {
  <HomebaseProvider>
    {/* ... */}
  </HomebaseProvider>
}

NOTE: If your server is at a different URL, you can specify the serverUrl prop on the HomebaseProvider:

<HomebaseProvider serverUrl={process.env.REACT_APP_BRAUSTIN_SERVER_URL}>

2. Use the useHomebase hook in consumer components

This will allow you to make authenticated graphQL calls using the homebaseGQL function.

import { useHomebase, GET_HOMES } from "@braustin-holdings/homebase-react"
import { useEffect, useState } from "react"

const HomeBaseClient = () => {
  const { homebaseGQL } = useHomebase()
  const [homes, setHomes] = useState([])

  useEffect(() => {
    getHomes()
  }, [])

  const getHomes = async () => {
    const res = await homebaseGQL(GET_HOMES)
    setHomes(res.data.homes)
  }

  return (
    <>
      <h3>Homes</h3>
      <pre>{JSON.stringify(homes, null, 2)}</pre>
    </>
  )
}
0.0.282

2 months ago

0.0.281

1 year ago

0.0.279

2 years ago

0.0.274

2 years ago

0.0.273

2 years ago

0.0.272

2 years ago

0.0.275

2 years ago

0.0.280

2 years ago

0.0.269

2 years ago

0.0.268

2 years ago

0.0.271

2 years ago

0.0.267

2 years ago

0.0.265

2 years ago

0.0.270

2 years ago

0.0.263

2 years ago

0.0.264

2 years ago

0.0.24

2 years ago

0.0.26

2 years ago

0.0.262

2 years ago

0.0.261

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.231

2 years ago

0.0.21

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago