Skip to content

Releases: atomic-state/http-react

v3.7.5

15 Dec 21:25
dd28544
Compare
Choose a tag to compare

v3.7.5

Enhancements

  • By default, useServerAction.auto will be false, making useServerMutation a deprecated function

v3.7.4

11 Dec 22:11
86d7d93
Compare
Choose a tag to compare

v3.7.4

Transform API

  • Similar to middleware but it transforms data on the fly without making a new request (happens instantly)
  • transform first checks data is not undefined before running, which makes sure it only runs when data or fallback data exist, preventing (most) runtime errors that could arise when manipulatind data that could be undefined.

Example usage:

"use client"

import useFetch from "http-react"
import { useState } from "react"

import { type TodoType } from "@/types/todo"

export default function Home() {
  const [showUppercase, setShowUppercase] = useState(false)

  const { data, isLoading } = useFetch<TodoType>(
    "https://jsonplaceholder.typicode.com/todos/2",
    {
      // Supports TypeScript out of the box
      transform(data) {
        if (showUppercase) {
          const transformedTodo = {
            ...data,
            title: data?.title.toUpperCase(),
          }
          return transformedTodo
        }
        return data
      },
    }
  )

  if (isLoading) return <p>Loading...</p>

  return (
    <main>
      <button onClick={() => setShowUppercase(!showUppercase)}>
        Uppercase: {showUppercase ? "ON" : "OFF"}
      </button>

      <h2>Title: {data.title}</h2>
    </main>
  )
}

v3.7.3

08 Dec 22:32
e415134
Compare
Choose a tag to compare

v3.7.3

Enhancements

  • Prevents unexpected side effects by avoiding setting global cache server side

v3.7.2

07 Dec 18:13
51d55f1
Compare
Choose a tag to compare

v3.7.2

Improvements:

  • Improves <Suspense> support
  • Improves Supense errors when no fallback data is provided

v3.6.7

22 Jul 21:54
1c8cc9b
Compare
Choose a tag to compare

Enhancements

  • Enhances caching with maxCacheAge with debounce

v3.6.6

21 Jul 20:34
1b37db6
Compare
Choose a tag to compare

Fixes

  • Fixes mutate not updating data after initial fetch

v3.6.4

12 Jul 00:30
04e2904
Compare
Choose a tag to compare

Important fix

  • Fixes errors not being returned in prod when using server actions

v3.6.3

08 Jul 01:42
f594fa2
Compare
Choose a tag to compare

Features and enhancements

  • Adds the function $searchParams that returns all searchParams
  • Enhances the useFetch function: the submit() method can be used with any data type

v3.5.7

30 Jun 19:29
71b4dd5
Compare
Choose a tag to compare

Enhancements

  • The jsonCompare fn can be used for shallow comparison

v3.5.6

29 Jun 19:47
9073a5e
Compare
Choose a tag to compare

Features

attempts can now be a function

Example usage (retry 4 times):

const { data } = useFetch("/api/data", {
  attempts({ status, res }) {
    if (status === 404) return // Don't retry 404s

    console.log("Failed to fetch ", res.url)
    return 4
  },
  attemptInterval: "2 sec",
})

You can always use a number as attempts