Skip to content

Releases: atomic-state/http-react

v2.3.2

04 Jan 15:05
ca5b39e
Compare
Choose a tag to compare

updated static typing for queryProvider

v2.2.9

04 Jan 09:25
1f22b54
Compare
Choose a tag to compare

Feat

When creating a provider (which returns a custom React hook), that hook call's return type will match exactly with the id passed as the first argument

v2.2.8

04 Jan 05:25
726dd0b
Compare
Choose a tag to compare

Feat

By default, the data property is returned in the resolver when using graphql queries

v2.2.7

04 Jan 03:47
89c240d
Compare
Choose a tag to compare

Feat

Improve typing when using graphql

v2.2.6

04 Jan 01:36
1224ae1
Compare
Choose a tag to compare

Feat: queryProvider 🚀

Added queryProvider function that accepts a dictionary with queries created with the gql function and returns a hook that is fully typed (using the static typing of the created queries).

Example:

import { gql, queryProvider } from 'http-react-fetcher'

/**
 * The characters result type
 */
export type CharactersResultType = {
  data: {
    characters: {
      results: {
        name: string
        status: string
        location: {
          name: string
        }
      }[]
    }
  }
}

// We add the type above to our characters' query
const charactersQuery = gql<CharactersResultType>`
  query {
    characters {
      results {
        name
        status
        location {
          name
        }
      }
    }
  }
`

// We create a dictionary with all our queries
const queries = {
  charactersQuery
}

// We create a hook that we can use across our app without the need to import a single query
// This also inherits all the config passed in the 'FetcherConfig' component and can be overwritten with the second argument.
const useQuery = queryProvider(queries)

export default function App() {
  // This is fully typed
  const { data } = useQuery('charactersQuery', {
    onResolve(data) {
      console.log(data)
    }
  })

  return (
    <div>
      <pre>{JSON.stringify(data, null, 2)}</pre>
    </div>
  )
}

v2.2.5

03 Jan 20:46
10c97ab
Compare
Choose a tag to compare

Fix

If revalidateOnMount is set to false, loading will be set to false if props haven't changed, and the error state will be preserved between renders unless props change or a request doesn't fail

v2.2.4

03 Jan 00:19
5f666e1
Compare
Choose a tag to compare

Feat

revalidateOnMount:

If false, revalidation will only happen when props passed to the useFetch change. For example, you may want to have a component that should fetch with useFetch only once during the application lifetime or when its props change but not when, for example, navigating between pages (web) or screens (React Native). This is very useful when you have components that should persist their state, like layouts. This is also a way of revalidating only when props change.

Note that the behaviour when props change is the same.

Example:

import { useFetcher } from 'http-react-fetcher'

export default function Page() {
  const { data } = useFetcher('/test', {
    revalidateOnMount: false,
    default: {}
  })

  return <pre>{JSON.stringify(data, null, 2)}</pre>
}

That component will fetch data only once during the application lifetime (even when navigating between pages or screens), or when any the props passed to the useFetcher call changes.

v2.2.3

02 Jan 18:33
0c8ed7a
Compare
Choose a tag to compare

fix(cdn links)

v2.2.2

01 Jan 23:43
f4a2781
Compare
Choose a tag to compare

Improve typing when using gql

v2.2.1

01 Jan 20:56
164f726
Compare
Choose a tag to compare

Fix

  • Prevent multiple calls of onResolve when unnecesary

Feat

  • By default, graphql queries are deduplicated using the object returned when using gql (this can be overwritten)

This is very useful. For example:

import { gql, useGql, useResolve } from 'http-react-fetcher'

const charactersQuery = gql`
  query getCharacters($page: Int) {
    characters(page: $page) {
      results {
        name
        image
      }
    }
  }
`

const Data = () => {
   const { data } = useGql(charactersQuery, {
    variables: {
      page: 2
    }
  })
  return <pre>{JSON.stringify(data, null, 2)}</pre>
}

const DataResolve = () => {
  useResolve(charactersQuery, data => {
    console.log('Data was fetched', data)
  })
  return null
}

export default function Page() {
  return (
    <>
      <DataResolve />
      <Data />
    </>
  )
}