Posts

Showing posts from November, 2019

scalajs & zio: react fetcher hooks and effects

scalajs & zio: react fetcher hooks and effects Hooks are relatively new in the react world. Hooks provide slices of capabilities to a component in a more composible model than class-based components. A “fetcher hook” fetches data and provides it to a react function component asynchrously as the data becomes available. The component must already be rendered to use a fetcher hook. I created a general scala.js react fetcher component in a previous blog . It works, but it is not a hook fetcher. Because it is not a hook, it is less flexible because it forces the application to use a specific component hierarchy. The fetcher in the blog is a react component–it returns a “dom” component. A react hook is not a component–a hook returns data and functions. The NPM registry is full of js/typescript react hook fetchers. They are easy to write. If a js Promise works for you, use them. Most hook implementations assume you are using HTTP transport via the browser’s “fetch”