1.0.49 - The schemas update
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>
}