0.15.5 • Published 4 years ago

react-offix-hooks v0.15.5

Weekly downloads
465
License
Apache-2.0
Repository
github
Last release
4 years ago

react-offix-hooks

Use offix-client in React hooks.

Documentation:

https://offix.dev

API

OffixProvider

import React from 'react'
import { render } from 'react-dom';

import { OfflineClient } from 'offix-client'
import { OffixProvider } from 'react-offix-hooks'

const offixClient = new OfflineClient(config)

const App = () => (
  <OffixProvider client={offixClient}>
    <MyRootComponent/>
  </OffixProvider>
)

render(<App />, document.getElementById('root'))

Usage With react-apollo-hooks

import React, { useState, useEffect } from 'react'
import { render } from 'react-dom';

import { OfflineClient } from 'offix-client'
import { OffixProvider } from 'react-offix-hooks'
import { ApolloProvider } from 'react-apollo-hooks'

const offixClient = new OfflineClient(clientConfig)

const App = () => {
  const [apolloClient, setApolloClient] = useState(null)

  // initialize the offix client and set the apollo client
  useEffect(() => {
    offixClient.init().then(setApolloClient)
  }, [])

  if (apolloClient) {
    return (
      <OffixProvider client={offixClient}>
        <ApolloProvider client={apolloClient}>
          <MyRootComponent/>
        </ApolloProvider>
      </OffixProvider>
    )
  }
  return <h2>Loading...</h2>
}


render(<App />, document.getElementById('root'))

useOfflineMutation

import gql from 'graphql-tag'
import { useOfflineMutation } from 'react-offix-hooks'

const ADD_MESSAGE_MUTATION = gql`
  mutation addMessage($chatId: String!, $content: String!) {
    addMessage(chatId: $chatId, content: $content)
  }
`

function addMessageForm({ chatId }) {
  const inputRef = useRef()

  const [addMessage] = useOfflineMutation(ADD_MESSAGE_MUTATION, {
    variables: {
      chatId,
      content: inputRef.current.value,
    }
  })

  return (
    <form>
      <input ref={inputRef} />
      <button onClick={addMessage}>Send Message</button>
    </form>
  )
}
0.16.0-beta1

4 years ago

0.16.0-alpha2

4 years ago

0.15.5

4 years ago

0.16.0-alpha

4 years ago

0.15.4

4 years ago

0.15.3

4 years ago

0.15.2

4 years ago

0.15.1

4 years ago

0.15.0

4 years ago

0.14.0

4 years ago

0.13.2

4 years ago

0.13.1

4 years ago

0.13.0

4 years ago

0.13.0-dev1

4 years ago

0.12.0

4 years ago

0.10.0

4 years ago

0.11.0

4 years ago

0.11.0-dev2

4 years ago

0.11.0-dev3

4 years ago

0.11.0-dev1

4 years ago

0.10.0-dev1

4 years ago

0.10.0-dev2

4 years ago

0.10.0-dev3

4 years ago

0.9.0

5 years ago

0.9.2-dev4

5 years ago

0.9.2-dev3

5 years ago

0.9.2-dev2

5 years ago

0.9.2-dev1

5 years ago

0.8.2

5 years ago

0.8.0

5 years ago

0.1.0

5 years ago