<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hellon Canella Machado on Medium]]></title>
        <description><![CDATA[Stories by Hellon Canella Machado on Medium]]></description>
        <link>https://medium.com/@helloncanella?source=rss-85c03b7a8310------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*N3IDXMIXmhGH1Gmyb6ZbhA.jpeg</url>
            <title>Stories by Hellon Canella Machado on Medium</title>
            <link>https://medium.com/@helloncanella?source=rss-85c03b7a8310------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 04:40:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@helloncanella/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[useParams — Extract parameters from the URL in one line.]]></title>
            <link>https://itnext.io/useparams-extract-parameters-from-the-url-in-one-line-e6d46bc170f1?source=rss-85c03b7a8310------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6d46bc170f1</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-router]]></category>
            <dc:creator><![CDATA[Hellon Canella Machado]]></dc:creator>
            <pubDate>Thu, 17 Oct 2019 13:08:36 GMT</pubDate>
            <atom:updated>2019-10-22T07:19:50.158Z</atom:updated>
            <content:encoded><![CDATA[<h3>useParams — Extract parameters from the URL in one line.</h3><p>The problem is simple: you need to extract some parameters from the browser’s URL. The id of a user, for example.</p><p>There are several possible solutions to this problem. The one I’ll show allow you to write:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dANB7_6Mh_UCEU7f.png" /></figure><p>Below, one of the possible forms the hook useParams can take:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0693c6b9f2f350ba9470a24af023277/href">https://medium.com/media/a0693c6b9f2f350ba9470a24af023277/href</a></iframe><p>Note the use of the hook <a href="https://www.npmjs.com/package/use-react-router">useRouter</a>. With it, you can get the properties of the route. The one we need here is location.pathname, the pathname that makes up the URL of the browser<em>.</em></p><p>In lines 8 and 9, we extract the parameters we need, giving to <a href="https://reacttraining.com/react-router/web/api/matchPath">matchPath</a> the pathname and the pattern we want to compare — (.*)?/account/:accountID/user/:userID.</p><p>The addition of (.*)? allows you to extract the same parameters from URLs like /any-thing/you-want/here/account/:accountID/user/:userID.</p><p>The variable pattern can take any value <a href="https://github.com/pillarjs/path-to-regexp/tree/v1.7.0">path-to-regexp@^1.7.0</a>understands.</p><p>If the browser’s URL matches the example’s pattern, we will get an object like {match:{userID: &#39;123456, accountID: &#39;ABC&#39;}}.</p><p>By returning the value of the key match we achieve our goal.</p><h3>Final Notes</h3><p>The hook <a href="https://www.npmjs.com/package/use-react-router">useRouter</a>depends you have installed the version 5.0.0 or newer of <a href="https://github.com/ReactTraining/react-router/blob/master/packages/react-router">react-router</a> or <a href="https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom">react-router-dom</a>.</p><p>Refer to the <a href="https://reacttraining.com/react-router/web/guides/quick-start">link</a> to get more details about the installation of those packages.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6d46bc170f1" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/useparams-extract-parameters-from-the-url-in-one-line-e6d46bc170f1">useParams — Extract parameters from the URL in one line.</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[useParams — Extraia parâmetros da URL em uma linha.]]></title>
            <link>https://medium.com/@helloncanella/useparams-extraia-par%C3%A2metros-da-url-em-uma-linha-f4a0511ed195?source=rss-85c03b7a8310------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4a0511ed195</guid>
            <category><![CDATA[react-router-4]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[hooks]]></category>
            <dc:creator><![CDATA[Hellon Canella Machado]]></dc:creator>
            <pubDate>Wed, 16 Oct 2019 17:28:53 GMT</pubDate>
            <atom:updated>2019-10-16T19:58:52.700Z</atom:updated>
            <content:encoded><![CDATA[<h3>useParams — Extraia parâmetros da URL em uma linha.</h3><p>O problema é simples: você precisa extrair alguns parâmetros da url do navegador. Um userID, por exemplo.</p><p>Existem diversas soluções possíveis para esse problema. A que vou mostrar permitirá escrever:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xTpgpUF1nIz1zjkYHGwxGA.png" /></figure><p>Abaixo, umas das possíveis formas que o hook useParams pode assumir:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0693c6b9f2f350ba9470a24af023277/href">https://medium.com/media/a0693c6b9f2f350ba9470a24af023277/href</a></iframe><p>Perceba o uso do hook <a href="https://www.npmjs.com/package/use-react-router">useRouter</a>. Com ele é possível obter as propriedades da rota. A que precisamos é location.pathname, a <em>pathname</em> que compõe a <em>url</em> do <em>browser</em>.</p><p>Nas linhas 8 e 9 extraímos os parâmetros de que necessitamos. Passamos para o utilitário <a href="https://reacttraining.com/react-router/web/api/matchPath">matchPath</a> a <em>pathname</em>, bem como padrão que desejamos comparar — (.*)?/account/:accountID/user/:userID.</p><p>A adição de (.*)? permite extrair os mesmos parâmetros de <em>urls</em> como /any-thing/you-want/here/account/:accountID/user/:userID.</p><p>A variável pattern pode assumir qualquer valor que <a href="https://github.com/pillarjs/path-to-regexp/tree/v1.7.0">path-to-regexp@^1.7.0</a> entenda.</p><p>Se a url do browser for compatível com o padrão do exemplo, receberemos um objeto do tipo {match:{userID: &#39;123456, accountID: &#39;ABC&#39;}}.</p><p>Ao retornar o valor de match, alcançamos nosso objetivo.</p><h4>Notas finais</h4><p>O hook <a href="https://www.npmjs.com/package/use-react-router">useRouter</a> depende que você tenha instalado a versão 5.0.0, ou mais recente, de <a href="https://github.com/ReactTraining/react-router/blob/master/packages/react-router">react-router</a> our <a href="https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom">react-router-dom</a>.</p><p>Consulte o <a href="https://reacttraining.com/react-router/web/guides/quick-start">link</a> para obter mais informações sobre a instalação desses dois pacotes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4a0511ed195" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[useAppState — Manage state with Apollo. But, in a few lines.]]></title>
            <link>https://medium.com/@helloncanella/manage-states-with-apollo-client-but-in-a-few-lines-172742b86cf4?source=rss-85c03b7a8310------2</link>
            <guid isPermaLink="false">https://medium.com/p/172742b86cf4</guid>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[apollo-client]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Hellon Canella Machado]]></dc:creator>
            <pubDate>Sat, 05 Oct 2019 15:27:22 GMT</pubDate>
            <atom:updated>2019-10-15T17:40:30.410Z</atom:updated>
            <content:encoded><![CDATA[<h3>useAppState — Manage state with Apollo, in a few lines.</h3><p>Anyone who has used <a href="https://github.com/apollographql/apollo-client">apollo-client</a> as a state manager knows it is a fantastic but bloated tool.</p><p>Changing an entry in a list of todos can be an uncomfortable task with a lot of boilerplate code — like the twenty-something lines of <a href="https://www.apollographql.com/docs/react/data/local-state/#writequery-and-readquery">code below</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8Blhc_aN-4QbttU0.png" /><figcaption><a href="https://www.apollographql.com/docs/react/data/local-state/#writequery-and-readquery">https://www.apollographql.com/docs/react/data/local-state/#writequery-and-readquery</a></figcaption></figure><p>Expecting to reduce the effort on jobs like these, I’ve been thinking of ways to make them a little simpler and more straightforward.</p><p>The question I’ve tried to answer recently was: is there a way to make this task as simple as using the hook <a href="https://reactjs.org/docs/hooks-state.html">useState</a>?</p><p>And yes, it is possible. In the next few lines, I will share the answer I found.</p><h3>useAppState</h3><p>The use of <a href="https://reactjs.org/docs/hooks-intro.html">hooks</a> is a powerful resource for structuring the behavior of our applications.</p><p>It’s amazing how many lines of code I’ve been saving by encapsulating the behavior of my components in these functions.</p><p>Since I adopted useState for the local state management of my components, I&#39;ve been looking for ways to do the same for a broader scope.</p><p>For this purpose, I wrote the package <a href="https://github.com/helloncanella/useAppState">useAppStat</a>e.</p><p><a href="https://github.com/helloncanella/useAppState">helloncanella/useAppState</a></p><p>With it, you can modify a cached state to, for example, open and close a floating menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*upABggaB-QL6GMaV.png" /></figure><p>We have above two isolated components that share the same state isOpen. At the same time, the hook provides a setter that allows the change of this value.</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Ftoggling-menu-6hvzf%3Ffontsize%3D14&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftoggling-menu-6hvzf%3Ffontsize%3D14&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc2158a43ebd228bf045b231c5856c8f/href">https://medium.com/media/fc2158a43ebd228bf045b231c5856c8f/href</a></iframe><h3>Variables</h3><p>You may assign variables to your queries as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/433a519f019a4260e0dd556c380e6b06/href">https://medium.com/media/433a519f019a4260e0dd556c380e6b06/href</a></iframe><p>We can illustrate this with an example involving two counters:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Ftwo-counters-wtjpb%3Ffontsize%3D14&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftwo-counters-wtjpb%3Ffontsize%3D14&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/efec761fc3ecf2154605fae1105d4b55/href">https://medium.com/media/efec761fc3ecf2154605fae1105d4b55/href</a></iframe><p>The components of this example are structured as follows.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b77d69f74811c2c88e007cb1fefb3080/href">https://medium.com/media/b77d69f74811c2c88e007cb1fefb3080/href</a></iframe><p>The way the display Counter and its controller AddOneButton are organized internally is shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f40f27729502c71c16a213f1efe30e1/href">https://medium.com/media/9f40f27729502c71c16a213f1efe30e1/href</a></iframe><p>The hook useCount encapsulates the behavior of our components as well as the details of interacting with our package, as detailed below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b71f879a565ef18d2043a918da9c5316/href">https://medium.com/media/b71f879a565ef18d2043a918da9c5316/href</a></iframe><p>Note the use of variables in the call of useAppState. It is the assignment of different values to label that gives independence to the states of the counters A and B.</p><h3>Updating queries without <a href="https://www.apollographql.com/docs/react/data/local-state/#local-resolvers">@client</a></h3><p>Although the above examples focus on updating <em>queries</em> with the <a href="https://www.apollographql.com/docs/react/data/local-state/#local-resolvers">@client</a> directive<em>, </em>useAppState can be used to update any cached data<em>.</em></p><p>Any list fetched from the server could be updated locally like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/202d9f2fbe0d2b97d8bf20bd9d41ee3b/href">https://medium.com/media/202d9f2fbe0d2b97d8bf20bd9d41ee3b/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftodolist-kyjel%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Ftodolist-kyjel%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fkyjel%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/56a7aa9e3f4038388e1c5709ffe570cc/href">https://medium.com/media/56a7aa9e3f4038388e1c5709ffe570cc/href</a></iframe><h3>Under the hood</h3><p>Internally, useAppState uses the hook <a href="https://www.apollographql.com/docs/react/api/react-hooks/#usequery">useQuery</a>, <a href="https://blog.apollographql.com/apollo-client-now-with-react-hooks-676d116eeae2">launched</a> in August 2019, to reactively access the state of the query. At the same time, a call to <a href="https://www.apollographql.com/docs/react/v2.5/advanced/caching/#writequery-and-writefragment">client.writeQuery</a> is encapsulated by its setter<em>.</em></p><p>The creation of this hook involved approximately 40 lines and is available at the <a href="https://github.com/helloncanella/useAppState/blob/master/src/useAppState.js">link</a>.</p><p>I hope this little utility allows you to write a little less boilerplate code :)</p><h3>Acknowledgment</h3><p>Thank you, <a href="https://www.linkedin.com/in/finnfrotscher/">@finnfrotscher</a> and <a href="https://twitter.com/aishablake?lang=en">@aishablake</a>, for your precious feedback.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=172742b86cf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gerencie estados com Apollo Client. Mas, em poucas linhas.]]></title>
            <link>https://medium.com/@helloncanella/gerencie-estados-com-apollo-client-mas-em-poucas-linhas-cc00506d318?source=rss-85c03b7a8310------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc00506d318</guid>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[state-management]]></category>
            <category><![CDATA[apollo]]></category>
            <category><![CDATA[apollo-client]]></category>
            <dc:creator><![CDATA[Hellon Canella Machado]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 14:44:21 GMT</pubDate>
            <atom:updated>2019-10-07T16:58:57.002Z</atom:updated>
            <content:encoded><![CDATA[<p>Quem está habituado a usar o <a href="https://github.com/apollographql/apollo-client">apollo-client</a> para o gerenciamento de estados, sabe que tem em mãos uma ferramenta fantástica, mas burocrática.</p><p>Uma simples alteração de uma lista de <em>todos</em> pode ser uma tarefa razoavelmente desconfortável, como as vinte e poucas linhas de <a href="https://www.apollographql.com/docs/react/data/local-state/#writequery-and-readquery">código abaixo</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I2Z_tXqXJ0smLVmDG9pYDA.png" /><figcaption><a href="https://www.apollographql.com/docs/react/data/local-state/#writequery-and-readquery">https://www.apollographql.com/docs/react/data/local-state/#writequery-and-readquery</a></figcaption></figure><p>Motivado por diminuir o esforço em tarefas como essas, venho pensando em formas de torná-las um pouco mais simples e diretas.</p><p>A pergunta que tentei responder nos últimos dias foi: será que há um modo de tornar essa tarefa tão simples quanto, por exemplo, utilizar o hook <a href="https://reactjs.org/docs/hooks-state.html">useState</a>?</p><p>E sim, é possivel. Nas próximas linhas, irei compartilhar a resposta que encontrei.</p><h3>useAppState</h3><p>O uso de <a href="https://reactjs.org/docs/hooks-intro.html"><em>hooks</em></a> tem se mostrado um recurso poderoso para estruturarmos o comportamentos das nossas aplicações.</p><p>É extraordinário o número de linhas de código que venho economizando, ao encapsular o comportamento dos meus componentes nessas funções.</p><p>Desde que adotei o useState para o gerenciamento local dos estados dos meus componentes, venho buscando formas de fazer o mesmo num escopo mais amplo.</p><p>Com esse objetivo escrevi o pacote <a href="https://github.com/helloncanella/useAppState">useAppStat</a>e.</p><p><a href="https://github.com/helloncanella/useAppState">helloncanella/useAppState</a></p><p>Com ele, você pode modificar um estado armazenado em <em>cache</em> para, por exemplo, abrir e fechar um menu flutuante.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m9dIzJfZFwKmal_yHh3d1A.png" /></figure><p>Temos acima dois componentes isolados que compartilham o mesmo estado isOpen. Ao mesmo tempo, o hook disponibiliza um <em>setter </em>que permite alterar<em> </em>este valor.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftoggling-menu-euqrk%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Ftoggling-menu-euqrk%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Feuqrk%2Fscreenshot.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/893de8c8c12286ce2c48c1e683c48642/href">https://medium.com/media/893de8c8c12286ce2c48c1e683c48642/href</a></iframe><h4>Variáveis</h4><p>Você pode atribuir variáveis às suas <em>queries </em>do seguinte modo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zEKog8l0QcPOcnuy9O8qJA.png" /></figure><p>Podemos ilustrar essa situação com um exemplo envolvendo dois contadores:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodesandbox.io%2Fs%2Ftwo-counters-wtjpb%3Ffontsize%3D14&amp;src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftwo-counters-wtjpb%3Ffontsize%3D14&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/efec761fc3ecf2154605fae1105d4b55/href">https://medium.com/media/efec761fc3ecf2154605fae1105d4b55/href</a></iframe><p>Os componentes desse exemplo estão estruturados dos seguinte modo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCXu6W6hMpkygIo74Ox32g.png" /></figure><p>Internamente, a forma como o mostrador Counter e o seu respectivo botão controlador AddOneButton estão organizados é mostrado abaixo:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nDlngxtNkNxoQ_suJynDag.png" /></figure><p>O hook useCount encapsula o comportamento dos nossos componentes, bem como os detalhes da interação com o nosso pacote, conforme detalhado a seguir:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5NKPnjyO2XfSqCaElGpT5w.png" /></figure><p>Observe o uso de variáveis na chamada de useAppState. É justamente a atribuição de valores diferentes para label que confere independência ao estados dos contadores A e B.</p><h4>Atualizando queries sem <a href="https://www.apollographql.com/docs/react/data/local-state/#local-resolvers">@client</a></h4><p>Apesar dos exemplos acima focarem na atualização de <em>queries</em> com a diretiva <a href="https://www.apollographql.com/docs/react/data/local-state/#local-resolvers"><em>@client</em></a><em>, </em>useAppState pode ser utilizado para atualizar qualquer dado mantido em <em>cache</em>.</p><p>Uma lista qualquer, extraída do servidor, poderia ser atualizada localmente mais ou menos assim</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-d9s8ysf8K-VumFdoieZRw.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Ftodolist-kyjel%3Ffontsize%3D14&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Ftodolist-kyjel%3Ffontsize%3D14&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fkyjel%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/56a7aa9e3f4038388e1c5709ffe570cc/href">https://medium.com/media/56a7aa9e3f4038388e1c5709ffe570cc/href</a></iframe><h3>“Debaixo dos pano”</h3><p>Internamente, useAppState utiliza o hook <a href="https://www.apollographql.com/docs/react/api/react-hooks/#usequery">useQuery</a>, <a href="https://blog.apollographql.com/apollo-client-now-with-react-hooks-676d116eeae2">lançado</a> em agosto de 2019, para acessar reativamente ao estado da query. Ao mesmo tempo, uma chamada a <a href="https://www.apollographql.com/docs/react/v2.5/advanced/caching/#writequery-and-writefragment">client.writeQuery</a> é encapsulada por seu <em>setter.</em></p><p>A elaboração desse hook envolveu aproximadamente 40 linhas, e está disponível no <a href="https://github.com/helloncanella/useAppState/blob/master/src/useAppState.js">link</a>.</p><p>Espero que esse pequeno utilitário lhe permita escrever um pouco menos :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc00506d318" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>