Skip to content

1.0.49 - The schemas update

Compare
Choose a tag to compare
@hazae41 hazae41 released this 29 Aug 23:00
· 844 commits to master since this release

NO BREAKING CHANGES

CHANGES

  • You can now use your favorite resources without using a hook, thanks to schemas and objects:
// Create a schema for your resource
function getHelloSchema(id: string) {
  return XSWR.single("/api/hello", fetchAsJson)
}

// Use it in a hook
function useHello(id: string) {
  const handle = XSWR.use(getHelloSchema(id))

  XSWR.useFetch(handle)
  return handle
}

// Or in a function
function Setter() {
  const { make } = XSWR.useXSWR()

  const set = useCallback(async () => {
    const object = make(getHelloSchema("123"))
    await object.mutate({ data: "hello world" })
    await object.refetch()
  }, [make])

  return <button onClick={set}>
    Click me
  </button>
}