You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Kyle, I am trying to use IO monad in React app(I don't know how much you are familiar with it), and I thought of using it as custom hook for every fetching side-effect needed in component. This is what I came up with so far:
And I can use it in some component to fetch some data like this:
import{isNotNil,logIf}from"./ContinentsSectionHelper";importuseIOfrom"../../hooks/useIO";import{IO}from"monio";import{chain,map,pipe,prop}from"ramda";//HelpersconstsendRequestForContinent=continent=>sendGetRequest(`https://corona.lmao.ninja/v3/covid-19/continents/${continent}?strict=true`)constsendGetRequest=url=>IO(()=>fetch(url))constcheckResponse=response=>response.ok? IO.of(response) : IO(()=>{throw"Oops something is wrong with response"})constgetResponseJson=response=>IO(()=>response.json())constfetchCountriesOfContinent=pipe(sendRequestForContinent,// send requestchain(checkResponse),// check if response is OKchain(getResponseJson),// convert response to JSONmap(prop('countries')),//get country property)//ComponentconstContinentsSection=()=>{constdata=useIO({sideEffectFunction: fetchCountriesOfContinent,args:['europe']})logIf(data)(isNotNil)return(<section><ContinentGraph/></section>)}exportdefaultContinentsSection;
Would you say that this example is one possible solution to using monio in react, and would you implement it in some other way?
The text was updated successfully, but these errors were encountered:
Hi Kyle, I am trying to use IO monad in React app(I don't know how much you are familiar with it), and I thought of using it as custom hook for every fetching side-effect needed in component. This is what I came up with so far:
And I can use it in some component to fetch some data like this:
Would you say that this example is one possible solution to using monio in react, and would you implement it in some other way?
The text was updated successfully, but these errors were encountered: