<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Matheus Ricelly</title>
    <description>The latest articles on DEV Community by Matheus Ricelly (@fsenaweb).</description>
    <link>https://dev.to/fsenaweb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F252841%2F4c3d9075-cd8d-4d95-ae2c-22471154aece.jpg</url>
      <title>DEV Community: Matheus Ricelly</title>
      <link>https://dev.to/fsenaweb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fsenaweb"/>
    <language>en</language>
    <item>
      <title>Introducing Hooks in React (useState)</title>
      <dc:creator>Matheus Ricelly</dc:creator>
      <pubDate>Sun, 02 May 2021 14:09:54 +0000</pubDate>
      <link>https://dev.to/fsenaweb/introducing-hooks-in-react-usestate-263l</link>
      <guid>https://dev.to/fsenaweb/introducing-hooks-in-react-usestate-263l</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4yir65gml4ctwzwn4pf.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4yir65gml4ctwzwn4pf.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hey guys!&lt;/p&gt;

&lt;p&gt;Although hooks are no longer a great novelty within React (since they have been introduced since version 16.8), there is still a large collection of documents that exemplify on the traditional model of development through classes in React components.&lt;/p&gt;

&lt;p&gt;I will write a series of introductory articles talking about the main React Hooks, among them, the &lt;strong&gt;useState&lt;/strong&gt; (which will be our first), &lt;strong&gt;useEffect&lt;/strong&gt; and &lt;strong&gt;useContext&lt;/strong&gt;, then we will pass through those a little more complex for some users, such as &lt;strong&gt;useRef&lt;/strong&gt;, &lt;strong&gt;useCallback&lt;/strong&gt;, &lt;strong&gt;useReducer&lt;/strong&gt;, among others. You can also create your own hook, this is very useful in certain situations (we can see in a next publication, leave your comment).&lt;/p&gt;

&lt;h1&gt;
  
  
  Theory
&lt;/h1&gt;

&lt;h3&gt;
  
  
  What is a hook?
&lt;/h3&gt;

&lt;p&gt;Well summarized, a hook is nothing more than a function that gives you access to certain features of a functional component of React (yes, functional component, since hooks do not work within classes), and that way you can access to your state and life cycle.&lt;/p&gt;

&lt;p&gt;And to have a good performance as states and lifecycles are rendered in the component, Hooks have a basic rule that specifies that it should never be used within loops, conditional rules (if, else for example) or nested functions, be aware of this rule!&lt;/p&gt;

&lt;h1&gt;
  
  
  Hands-on
&lt;/h1&gt;

&lt;h3&gt;
  
  
  useState
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This hook is responsible for manipulating the &lt;em&gt;state&lt;/em&gt; of your application. It returns to us an array where we have a value and a function that when invoked will have a responsibility to change the information of this value.&lt;/p&gt;

&lt;p&gt;We can pass an initial value when the initial rendering of the component occurs. This value is the same signpost within the initial argument in useState (&lt;strong&gt;initialState&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;In this example, &lt;strong&gt;setState&lt;/strong&gt; is used when we want to update that state variable within the component. It receives the new value informed and instead of updating immediately, it queues that value, thus passing the most recent value to this variable, this process is well known in the react by &lt;strong&gt;immutability&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;An alternative, and you can find in several codes, it is the possibility of invoking the function that updates the status with a callback, taking the same previous example, could refactor it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevState&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;nextState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That way the new state based on the previous one returns. Due to immutability, this is widely used in some applications where we want to make some comparisons on state changes for screen animations, for example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Already when we use the &lt;em&gt;TypeScript&lt;/em&gt;, we infer the state type as in the above example &lt;code&gt;useState&amp;lt;string&amp;gt;('value')&lt;/code&gt;. However, it is worth mentioning, that for primary types (such as strings, number, boolean, for example) you do not need to make the type explicit because the typescript interpreter can dynamically define them, leaving that way, the cleaner code Thus avoiding an error if a different data type is informed.&lt;/p&gt;

&lt;p&gt;A more complete example about using type in useState with TypeScript you can be below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ProductProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
  &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProduct&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ProductProps&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Samsung Galaxy S20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1999&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Headset Misoftsot LX-300&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;79&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mouse Gamer Corsair&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;449&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;])&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; 
          &lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above, very simple, show how to pass an array of products, inside the useState. With this, in addition to testing the use of array (which is another type allowed inside the useState), we can verify how to proceed with this typing through the typescript and infer within the code perform the listing for view on the page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tips that are essential in using useState
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;As good practice, always try to call the useState Hooks at the beginning of the component. Even if you position it in different places, React will try to organize so that your code works, however, you will present several warnings in your devtools.&lt;/p&gt;

&lt;p&gt;Avoid creating Usestate within loops, conditional or some nested function, this can cause various errors in the rendering of your component, damaging your project.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It's from this introductory line, that you can deepen a little more of your knowledge within React and React Hooks. Explore your knowledge and studies in this React functionality that allows you to help in various tasks in your applications. You can have all the information about Hooks in &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;Official Documentation&lt;/a&gt; or a &lt;a href="https://reactjs.org/docs/hooks-reference.html#usestate" rel="noopener noreferrer"&gt;Detailed Reference of Usestate&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;If you liked this article, be sure to share and comment. If you want to know a little more, change some ideas, you can leave the comments your opinion on the subject and even suggest something for the upcoming articles.&lt;/p&gt;

&lt;p&gt;Enjoy and get to know a little of my jobs, visiting the site &lt;a href="https://www.fsenaweb.me" rel="noopener noreferrer"&gt;www.fsenaweb.me&lt;/a&gt;. It's has my portfolio, my social networks (including &lt;a href="https://github.com/fsenaweb/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, where you have a few applications of examples to practice), and contacts links.&lt;/p&gt;




&lt;p&gt;And that's it, until next time! My name is &lt;em&gt;Matheus Ricelly&lt;/em&gt;, and for his attention, my thank you!&lt;/p&gt;

</description>
      <category>react</category>
      <category>hooks</category>
      <category>usestate</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Introdução aos Hooks no React (useState)</title>
      <dc:creator>Matheus Ricelly</dc:creator>
      <pubDate>Sun, 02 May 2021 14:03:38 +0000</pubDate>
      <link>https://dev.to/fsenaweb/introducao-aos-hooks-no-react-usestate-5223</link>
      <guid>https://dev.to/fsenaweb/introducao-aos-hooks-no-react-usestate-5223</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fknuytd1iz213wy5j3l08.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fknuytd1iz213wy5j3l08.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Olá Pessoal!&lt;/p&gt;

&lt;p&gt;Apesar dos Hooks não serem mais uma grande novidade dentro do React (pois foram introduzidos desde a versão 16.8), ainda existe um grande acervo de documentos que exemplificam sobre o modelo tradicional de desenvolvimento através de classes nos componentes do React.&lt;/p&gt;

&lt;p&gt;Irei escrever uma série de artigos introdutórios falando sobre os principais Hooks do React, entre eles, o &lt;strong&gt;useState&lt;/strong&gt; (que será nosso primeiro), &lt;strong&gt;useEffect&lt;/strong&gt; e &lt;strong&gt;useContext&lt;/strong&gt;, logo em seguida, passaremos por aqueles um pouco mais complexas para alguns usuários, como &lt;strong&gt;useMemo&lt;/strong&gt;, &lt;strong&gt;useRef&lt;/strong&gt;, &lt;strong&gt;useCallback&lt;/strong&gt;, &lt;strong&gt;useReducer&lt;/strong&gt;, entre outros. Você também pode criar seu próprio Hook, isso é muito útil em determinadas situações (poderemos ver numa próxima publicação, deixe o seu comentário).&lt;/p&gt;

&lt;p&gt;Tentarei explicar de uma forma bem introdutória e clara (utilizando exemplos com Javascript e TypeScript), com a intenção de auxiliar aos desenvolvedores que estão iniciando nessa carreira do desenvolvimento front-end com o React (Web e Native) e que pode ser aplicado dentro dos frameworks mais populares como o Gatsby, Next.js e React Native.&lt;/p&gt;

&lt;h1&gt;
  
  
  Teoria
&lt;/h1&gt;

&lt;h3&gt;
  
  
  O que é um Hook?
&lt;/h3&gt;

&lt;p&gt;De forma bem resumida, um Hook nada mais é que uma função que te dá acesso a determinados recursos de um componente funcional do React (sim, componente funcional, pois os Hooks não funcionam dentro de Classes), e dessa forma, você pode ter acesso ao seu estado e ciclo de vida. &lt;/p&gt;

&lt;p&gt;E para ter uma boa performance da forma como os estados e os ciclos de vida são renderizados no componente, os Hooks tem uma regrinha básica que especifica que nunca deve ser utilizado dentro de loops, regras condicionais (if, else por exemplo) ou funções aninhadas, fique atento a essa regra!&lt;/p&gt;

&lt;h1&gt;
  
  
  Mão na massa
&lt;/h1&gt;

&lt;h3&gt;
  
  
  useState
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;initialState&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Esse Hook é o responsável por manipular o state da sua aplicação. Ele nos retorna um array onde temos um valor e uma função que ao ser invocada terá responsabilidade de alterar a informação desse valor. &lt;/p&gt;

&lt;p&gt;Podemos passar um valor inicial, quando ocorre a renderização inicial do  componente. Esse valor é o mesmo sinalizado dentro do argumento inicial em useState(&lt;strong&gt;initialState&lt;/strong&gt;).&lt;/p&gt;

&lt;p&gt;Já nesse exemplo, o &lt;strong&gt;setState&lt;/strong&gt; é utilizado quando queremos atualizar aquela variável de estado dentro do componente. Ele recebe o novo valor informado e em vez de atualizar de forma imediata, ele enfileira esse valor, passando assim o valor mais recente a essa variável, esse  processo é bem conhecido no React por &lt;strong&gt;imutabilidade&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Uma outra alternativa, e que poderá encontrar em diversos códigos, é a possibilidade de se invocar a função que atualiza o estado com um retorno de chamada, pegando o mesmo exemplo anterior, poderia refatorá-lo assim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;prevState&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;nextState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dessa forma retorna-se  o novo estado com base no anterior. Devido a imutabilidade, isso é muito utilizado em algumas aplicações onde queremos fazer algumas comparações em mudanças de estado para animações em tela, por exemplo.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Já quando utilizamos o &lt;em&gt;TypeScript&lt;/em&gt;, inferimos o tipo do estado como no exemplo acima &lt;code&gt;useState&amp;lt;string&amp;gt;('value')&lt;/code&gt;. Porém, vale ressaltar, que para tipos primários (como strings, number, boolean, por exemplo) você não precisa tornar o tipo explícito, pois o interpretador do TypeScript consegue defini-los de forma dinâmica, deixando dessa forma, o código mais limpo e evitando assim um erro caso seja informado um tipo de dado diferente.&lt;/p&gt;

&lt;p&gt;Um exemplo mais completo sobre o uso de tipo no useState com o TypeScript você pode ser abaixo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ProductProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;
  &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Product&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setProduct&lt;/span&gt; &lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ProductProps&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Samsung Galaxy S20&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1999&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Headset Misoftsot LX-300&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;79&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Mouse Gamer Corsair&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;449&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;])&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;ul&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt; 
          &lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;li&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/li&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;          &lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/ul&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Acima, de forma bem simples, mostro como passar um array de produtos, dentro do useState. Com isso, além de testarmos a utilização de Array (que é mais um tipo permitido dentro do useState), podemos verificar como proceder com essa tipagem através do TypeScript e inferir dentro do código realizar a listagem para exibição na página.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dicas que são essenciais no uso do useState
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Como boa prática, procure sempre chamar os hooks useState no início do componente. Mesmo que você o posicione em locais diferentes, o React irá tentar organizar para que seu código funcione, porém, apresentará diversos warnings em seu DevTools.&lt;/p&gt;

&lt;p&gt;Evite criar useState dentro de loops, condicionais ou em algum função aninhada, isso pode causar diversos erros na renderização do seu componente, prejudicando o seu projeto.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;É a partir dessa linha introdutória, que você poderá aprofundar um pouco mais dos seus conhecimentos dentro do React e o React Hooks. Explore um pouco os seus conhecimentos e estudos nessa funcionalidade do React que te permite ajudar em diversas tarefas nas suas aplicações. Você pode ter todas as informações sobre os Hooks na &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;documentação oficial&lt;/a&gt; ou uma &lt;a href="https://reactjs.org/docs/hooks-reference.html#usestate" rel="noopener noreferrer"&gt;referência detalhada do useState&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;Se você gostou desse artigo, não deixe de compartilhar e comentar. Se você quiser saber um pouco mais, trocar algumas idéias, poderá deixar nos comentários sua opinião sobre o assunto e até sugerir algo para os próximos artigos.&lt;/p&gt;

&lt;p&gt;Aproveite e conheça um pouco dos meus trabalhos, visitando o site &lt;a href="https://www.fsenaweb.me" rel="noopener noreferrer"&gt;www.fsenaweb.me&lt;/a&gt;. Ele tem o meu portfólio, minhas redes sociais (inclusive o &lt;a href="https://github.com/fsenaweb/" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; , onde você tem a disposição algumas aplicações de exemplos para poder praticar), e links  para contatos.&lt;/p&gt;

&lt;p&gt;Se você já desenvolve com o React e deseja ampliar os conhecimentos, eu indico um excelente curso, do Willian Justen, chamado &lt;a href="https://reactavancado.com.br" rel="noopener noreferrer"&gt;React avançado&lt;/a&gt;, onde ele aborda de uma maneira super didática como trabalhar com o React, utilizando conceitos avançados, montando um projeto prático, realizando testes unitários, testes de integração e muito mais, vale a pena o investimento.&lt;/p&gt;




&lt;p&gt;E é isso, até a próxima! Meu nome é &lt;em&gt;Matheus Ricelly&lt;/em&gt;, e pela sua atenção, o meu muito obrigado !&lt;/p&gt;

</description>
      <category>react</category>
      <category>hooks</category>
      <category>usestate</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Conhecendo e desenvolvendo filtros no Vue.js</title>
      <dc:creator>Matheus Ricelly</dc:creator>
      <pubDate>Thu, 25 Jun 2020 13:04:47 +0000</pubDate>
      <link>https://dev.to/fsenaweb/conhecendo-e-desenvolvendo-filtros-no-vue-js-2jpk</link>
      <guid>https://dev.to/fsenaweb/conhecendo-e-desenvolvendo-filtros-no-vue-js-2jpk</guid>
      <description>&lt;p&gt;Olá pessoal!&lt;/p&gt;

&lt;p&gt;Nesse artigo, de forma especial, irei falar sobre uma funcionalidade que na minha opinião é pouco utilizada (ou comentada) dentro da comunidade Vue.js, que são os Filtros. Assim como os Plugins, Diretivas Personalizadas e os Mixins, os filtros fazem parte das funcionalidades reutilizáveis dentro do Vue, auxiliando no processo de criação de componentes.&lt;/p&gt;

&lt;p&gt;Nos componentes do Vue, os filtros são funcionalidades que nos permitem obter diversas formatações na saída dos dados dinâmicos do seu estado. Ou seja, eles não alteram os dados de um componente, apenas podem formatar seus dados na renderização.&lt;/p&gt;

&lt;h2&gt;
  
  
  Filtros locais
&lt;/h2&gt;

&lt;p&gt;Conforme a documentação oficial, a utilização dos filtros ocorrem dentro de interpolações mustache e expressões v-bind. Veja um exemplo da formatação do filtro no template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- em interpolações de texto --&amp;gt;&lt;/span&gt; 
{{ message | capitalize }}  
&lt;span class="c"&gt;&amp;lt;!-- em interligações de atributos --&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-bind:text=&lt;/span&gt;&lt;span class="s"&gt;"message | capitalize"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
Criando de forma local, dentro do componente, podemos ter:
filters: {
   capitalize(value) {
     if (!value) return ''
     value = value.toString()
     return value.charAt(0).toUpperCase() + value.slice(1)
   }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nesse primeiro exemplo, extraído da própria documentação, podemos analisar que a função capitalize apenas pega o valor passar e faz o tratamento com os métodos necessários para que se obtenha o resultado, não existindo nenhuma interferência no valor original do estado do componente.&lt;/p&gt;

&lt;p&gt;Em algumas situações, os Filtros podem ser bem semelhantes as Propriedades Computadas, com a diferença de que nos filtros, os dados não são transformados, eles apenas alteram a saída e retornam uma versão com o determinada filtragem da informação. Assim, não é gerado um novo valor para aquele dado do componente.&lt;/p&gt;

&lt;h2&gt;
  
  
  Filtros Globais
&lt;/h2&gt;

&lt;p&gt;Tem certas situações onde determinado filtro poderá ser usado em diversos componentes dentro da sua aplicação, principalmente naqueles projetos maiores, onde pode ocorrer diversas interações do sistema ao longo do projeto.&lt;br&gt;
Para isso, existe a possibilidade de se criar os filtros globais, e assim como disse anteriormente, igualmente aos mixins, plugins, entre outros, eles ficam disponíveis em qualquer parte do seu projeto, facilitando a sua utilização e o reaproveitamento dos códigos.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;capitalize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
   &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;charAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
   &lt;span class="c1"&gt;// sua instância do Vue...&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nesse exemplo vemos a criação de um filtro global, utilizando a propriedade .filter dentro do arquivo main.js. Caso sua aplicação utilize muitos filtros, por questão de organização, é recomendado criar um arquivo separado e colocar todos os filtros neles e fazer o import dentro do arquivo main.js. E tem um detalhe que é muito importante e deve sempre ser lembrado: quando um filtro global possuir o mesmo nome de um filtro local, o filtro local terá prioridade.&lt;/p&gt;

&lt;p&gt;Como os filtros são funções JavaScript, eles aceitam o valor a ser transformado como o primeiro parâmetro. Você também pode passar quantos argumentos achar necessários de acordo com a necessidade da sua aplicação.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;filterA&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;arg1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arg2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assim como podemos passar diversos argumentos, é possível encadear diversos filtros, para isso basta utilizarmos o símbolo pipe (|) e através de diversos filtros transformadores, obtermos único valor.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;filters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Upper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;

    &lt;span class="nx"&gt;Lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;E dentro do valor, utilizamos da seguinte forma:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Upper&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Lower&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Claro que esse exemplo não teria nenhuma funcionalidade, mas apenas para exemplificar que é possível colocarmos diversos filtros dentro de um único valor, e como eu mencionei que são encadeadas, a função Lower será executada após obter o resultado de Upper, sendo passado como o único argumento de Lower.&lt;/p&gt;

&lt;p&gt;Explore um pouco os seus conhecimentos e estudos nessa funcionalidade do Vue.js que te permite ajudar em diversas tarefas nas suas aplicações. Veja mais na &lt;a href="https://vuejs.org/"&gt;documentação oficial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Se você gostou desse artigo, não deixe de compartilhar e comentar. Se você quiser saber um pouco mais, trocar algumas idéias, poderá deixar nos comentários sua opinião sobre o assunto e até sugerir algo para os próximos artigos.&lt;/p&gt;

&lt;p&gt;Aproveite e conheça um pouco dos meus trabalhos, visite o site &lt;a href="https://www.fsenaweb.me"&gt;www.fsenaweb.me&lt;/a&gt;, ele tem o meu portfólio, minhas redes sociais (inclusive o &lt;a href="https://github.com/fsenaweb"&gt;GitHub&lt;/a&gt;, onde você tem a disposição algumas aplicações de exemplos para praticar com o Vue.js), e um pequeno espaço para contatos.&lt;/p&gt;

&lt;p&gt;E não deixe de participar de nosso grupo no Telegram (&lt;a href="https://t.me/vuejsbrasil"&gt;VueJS Brasil&lt;/a&gt;), tem uma galeria muito especial pronta trocar outras experiências.&lt;/p&gt;

&lt;p&gt;E é isso, até a próxima! Meu nome é Matheus Ricelly , e pela sua atenção, o meu muito obrigado !&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>filtros</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Knowing and developing filters in Vue.js</title>
      <dc:creator>Matheus Ricelly</dc:creator>
      <pubDate>Sat, 08 Feb 2020 16:46:31 +0000</pubDate>
      <link>https://dev.to/fsenaweb/knowing-and-developing-filters-in-vue-js-5g2</link>
      <guid>https://dev.to/fsenaweb/knowing-and-developing-filters-in-vue-js-5g2</guid>
      <description>&lt;p&gt;Hi guys!&lt;/p&gt;

&lt;p&gt;In this article, in a special way, I will talk about a feature that in my opinion is little used (or commented on) within the Vue.js community, which are Filters. Like Plugins, Custom Directives and &lt;a href="https://dev.to/fsenaweb/how-to-work-with-mixins-on-vue-js-2cja"&gt;Mixins&lt;/a&gt;, filters are part of the reusable features within Vue, helping in the process of creating components.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In Vue components, filters are functionalities that allow us to obtain different formats in the output of the dynamic data of its state. That is, they do not change the data of a component, they can only format their data in rendering.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Local filters&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;According to the official documentation, the use of filters occurs within mustache interpolations and v-bind expressions. See an example of the formatting of the filter in the template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- in interpolations text --&amp;gt;&lt;/span&gt; 
{{ message | capitalize }}  
&lt;span class="c"&gt;&amp;lt;!-- in attribute interconnections --&amp;gt;&lt;/span&gt; 
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;v-bind:text=&lt;/span&gt;&lt;span class="s"&gt;"message | capitalize"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Creating locally, within the component, we can have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;filters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nx"&gt;capitalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
     &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;charAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this first example, extracted from the documentation itself, we can analyze that the capitalize function just takes the value through and does the treatment with the necessary methods to obtain the result, with no interference in the original value of the component's state.&lt;/p&gt;

&lt;p&gt;In some situations, the Filters can be very similar to the Computed Properties, with the difference that in the filters, the data is not transformed, they just change the output and return a version with the determined filtering of the information. Thus, a new value is not generated for that component data.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Global Filters&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;There are certain situations where a particular filter can be used on several components within your application, especially in those larger projects, where several interactions of the system can occur throughout the project.&lt;/p&gt;

&lt;p&gt;For this, there is the possibility of creating global filters, and just as I said earlier, equally to mixins, plugins, among others, they are available anywhere in your project, facilitating their use and the reuse of codes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;capitalize&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;
   &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
   &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;charAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
   &lt;span class="c1"&gt;// your Vue instance...&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we see the creation of a global filter, using the .filter property inside the main.js. If your application uses many filters, for organization reasons, it is recommended to create a separate file and place all filters in them and import them into the main.js file. And there is a detail that is very important and should always be remembered: when a global filter has the same name as a local filter, the local filter will have priority.&lt;/p&gt;

&lt;p&gt;Since filters are JavaScript functions, they accept the value to be transformed as the first parameter. You can also pass as many arguments as you need according to the needs of your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;filterA&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;arg1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;arg2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just as we can pass several arguments, it is possible to link several filters, for that we just need to use the pipe symbol (|) and through several transforming filters, we obtain a single value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;filters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Upper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;

    &lt;span class="nx"&gt;Lower&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And within the value, we use it as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Upper&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nx"&gt;Lower&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of course, this example would have no functionality, but just to exemplify that it is possible to put several filters within a single value, and as I mentioned that they are chained, the Lower function will be executed after obtaining the result of Upper, being passed as the only one Lower's argument.&lt;/p&gt;

&lt;p&gt;Explore your knowledge and studies a little in this Vue.js feature that allows you to help with various tasks in your applications. See more in the official documentation.&lt;/p&gt;




&lt;p&gt;If you liked this article, be sure to share and comment. If you want to know a little more, exchange some ideas, you can leave your opinion on the subject in the comments and even suggest something for the next articles.&lt;/p&gt;

&lt;p&gt;Enjoy and get to know a little of my work, visit the website &lt;a href="http://www.fsenaweb.me"&gt;www.fsenaweb.me&lt;/a&gt;, it has my portfolio, my social networks (including &lt;a href="https://github.com/fsenaweb"&gt;GitHub&lt;/a&gt;, where you have some sample applications to practice with Vue.js), and a small space for contacts.&lt;/p&gt;

&lt;p&gt;And be sure to join our group and Vue.js in Brazil, through Telegram (&lt;a href="https://t.me/vuejsbrasil"&gt;VueJS Brasil&lt;/a&gt;), has a very special gallery ready to exchange other experiences.&lt;/p&gt;

&lt;p&gt;That's it, see you next time! My name is Matheus Ricelly, and for your attention, my thanks!&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>filters</category>
    </item>
    <item>
      <title>How to work with mixins on Vue.js</title>
      <dc:creator>Matheus Ricelly</dc:creator>
      <pubDate>Fri, 18 Oct 2019 18:03:20 +0000</pubDate>
      <link>https://dev.to/fsenaweb/how-to-work-with-mixins-on-vue-js-2cja</link>
      <guid>https://dev.to/fsenaweb/how-to-work-with-mixins-on-vue-js-2cja</guid>
      <description>&lt;p&gt;Through my work with Vue, I have gained experience in developing components and reusing them in applications, thus gaining agility, time, resources, among others. And in recent projects I had come to realize that some of my components had very similar code, including some methods, computed properties.&lt;/p&gt;

&lt;p&gt;It was a lot of code that I practically copied and pasted from one component to another, changing small details and that caught my attention, so I went to get more information on the internet, mainly in the documentation of Vue.js itself, and also in telegram, in the Vuejs Brasil group. I found out that there is a fantastic feature that is Mixins, where the documentation itself gives a clear explanation:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Mixins are a flexible way to distribute reusable functionalities for Vue components. A mixin object can contain any component options. When a component uses a mixin, all options in the mixin will be “mixed” into the component’s own options.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Clearer than that, impossible, isn’t it ?! Mixins allow you to have methods, props, data, computed properties applied to various components. They closely resemble an approach to having an inheritance composition (those same inheritances we find in C #, Java, and other languages). Well, after that, I saw that my work on code reuse has slowed down a lot, making it even faster to build my applications. But let’s stop talking and let’s practice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s go to the example!
&lt;/h2&gt;

&lt;p&gt;Inside your Vue application, we will create a folder called mixins, where we will put files with extension .js to import in the components where we will take advantage of the codes in the application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In my case, I will use some words in the Portuguese language, but nothing is changed in the use of features.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D27fgl9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1056/1%2A1dJ50HokwxdxG_2FEwVvkw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D27fgl9V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1056/1%2A1dJ50HokwxdxG_2FEwVvkw.png" alt="We call this file named nomeMixins.js" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this first example (nomeMixins.js) I created a constant named nomeMixins and returned an object, just as we do in the Vue instance itself containing three simple properties for our study. Now we can import the nomeMixins.js file into the component:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--O_sgBKUA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/904/1%2A4Qt1hLC-h7mTOY8OYBCiaQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--O_sgBKUA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/904/1%2A4Qt1hLC-h7mTOY8OYBCiaQ.png" alt="Part of the .vue component with the nomeMixins import" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Initially we made the import (import nomeMixins …) and declared mixins and assigned the value declared in import, in this case being mixins: [nomeMixins], where you can insert several other files through an array.&lt;/p&gt;

&lt;p&gt;Not only with the data() we can work with, as I said earlier, you can work with methods, computed properties, and many others. Continuing, in the same file nameMixins.js, we will insert a computed property, where it will join 2 properties of the object in data (), which follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GBeNPdn2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1408/1%2AHqXi0aVSXreueCTQx2k-mA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GBeNPdn2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/1408/1%2AHqXi0aVSXreueCTQx2k-mA.png" alt="Example code" width="800" height="417"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the .vue component, we don’t need to add anything, since it already understands that that computed property will be part of it, so just call it inside the   tag or via a console.log () to view the result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r6JeTcYI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/752/1%2AZOvufRYZ62MKSJF07aEPtA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r6JeTcYI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/752/1%2AZOvufRYZ62MKSJF07aEPtA.png" alt="Example code" width="752" height="292"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This saves you line after line of code for activities that are repetitive on your site or application with Vue.js. There are several possibilities for this reuse, including a way to produce a &lt;strong&gt;global mixin&lt;/strong&gt; where you can use it in all instances of Vue, but the documentation itself recommends caution, as this may affect other parts of your code.&lt;/p&gt;

&lt;p&gt;You can find more information in the &lt;a href="https://vuejs.org"&gt;official Vue.js documentation&lt;/a&gt;, containing many examples of using mixins in your application, go there and check it out.&lt;/p&gt;

&lt;p&gt;If you enjoyed this article, be sure to share and comment. If you want to know a little more, exchange some ideas (I’m still improving my English, but we can talk), you can leave your comments on the subject and even suggest something for the next articles.&lt;/p&gt;

&lt;p&gt;Enjoy and know a little of my work, visit the site &lt;a href="https://www.fsenaweb.dev"&gt;www.fsenaweb.dev&lt;/a&gt;, he has my portfolio, my social networks (including &lt;strong&gt;GitHub&lt;/strong&gt;, where you have available some sample applications to practice with Vue.js), and a small space for contacts.&lt;/p&gt;


&lt;div class="ltag__user ltag__user__id__252841"&gt;
    &lt;a href="/fsenaweb" class="ltag__user__link profile-image-link"&gt;
      &lt;div class="ltag__user__pic"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r4meOI1I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--a62trfUa--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/252841/4c3d9075-cd8d-4d95-ae2c-22471154aece.jpg" alt="fsenaweb image"&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;div class="ltag__user__content"&gt;
    &lt;h2&gt;
&lt;a class="ltag__user__link" href="/fsenaweb"&gt;Matheus Ricelly&lt;/a&gt;Follow
&lt;/h2&gt;
    &lt;div class="ltag__user__summary"&gt;
      &lt;a class="ltag__user__link" href="/fsenaweb"&gt;Career developed in the Information Technology area, with experience and academic training in web systems development.&lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;And that’s it, see you next time! &lt;strong&gt;My name is Matheus Ricelly, and for your attention, thank you very much!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>mixins</category>
    </item>
  </channel>
</rss>
