Execute asynchronous tasks with useEffect clean and safely

From calling an API to set a timeout delay, I am sure you already questioned how to do it properly when using the React hook useEffect . If that sounds still blurred, then this article is for you. If not, you may at least learn a different approach to get the job done or feel more confident while doing it.

I will present 3 ways of doing it safely and tidy. But first, I want to show what you should NOT do.

What you should NOT do ❌

Don’t do the async task directly in the useEffect, instead…

Many times we use the React Context API to share top-to-bottom states. However, a simple approach can be taken instead.

A common scenario is when we want to control a component state from its children. Don’t know what I am talking about? Keep going, you will get it, I promise.

Let’s jump straight into it. What you see below is what we will call a MenuTrigger. So when a user clicks on the user icon, the menu content appears.

We want to build this component in a way that we can pass whatever content for the menu and yet, be able to close it when the user clicks in any item of the menu.

Designing the component

Many times we want to control parts of our app by modifying the query string parameters. Learn how you can do it by using React hooks.

To illustrate that we're going to use a simple Tabs component. The idea is:
once the selected tab changes, the query string parameters are updated accordingly. In the same way, if you load your component with a valid query parameter in place, the component will initialize its state accordingly.

Display any kind of data using the same table component while enjoying the benefits of typescript features.

A very common use case is to be able to list multiple types of data using tables. This happens quite frequently in dashboards for instance.

For example, an e-commerce dashboard might want to display a table to list the items they have in their stock, and in another table, they want to display the list of client addresses.

When using React with Typescript we want to explore as much as possible the typing benefits it brings to us by creating a consistent component…

Toggling Modal visibility; hiding, and showing messages, there are many scenarios where you’ll find yourself writing the same code. But there's a solution: useBooleanState

The useBooleanState hook

Going straight to the code, this is how it looks:

How to use it?

I give you an example. Let’s say you want to toggle a Modal visibility. One option would be something like this:

Say goodbye to HOCs or connectors and welcome the React hooks era


  • Can React hooks and Redux coexist?
  • TL;DR: Focus on the integration between your app state and the components
  • Connecting components using hooks
  • Conclusion

Can Rect hooks and Redux coexist?

I will say it, React hooks and Redux can and should coexist. Especially when you already have Redux holding your application state, there is no reason to drop it off and start from scratch just because you can write a reducer using hooks. Let redux do what it does best and instead, focus on the integration between your app state and the components.

Politeia is a powerful off-chain governance tool. It empowers users to submit detailed proposals, provides a platform to review them, and allows users to vote which proposals should receive funding from the project treasury. Politeia is designed for Decred, but its code is open source and can be used by anyone. This post gives an overview of the Politeia system architecture.

For those of you who are not familiar with what Politeia is, I will recite the title of this blog post from Decred’s project lead (Jake Yocom-Piatt):

Politeia: Proposals in a Timestamped Filesystem

Expanding this a bit more: Politeia…

Duas noites de lua cheia e nenhum pensamento,

nenhum pensamento digno de duas luas.

Muito sonhos talvez e sonhos…

sonhos distanciam da realidade que traz os pensamentos.

A inspiração do sonho acordado

contra a recapitulação do sonho dormido.

É a fé do amanhã

e a percepção misteriosa do agora

é o mistério e a realidade nua

é a parte obvia e esperada (e desesperada)

é o místico do amanhecer

é conformidade e a revolução

é seu (meu) medo de querer

mais do que diz a televisão

é a vida sem sermão

Qual a barreira existente para se encontrar qualquer informação no dia de hoje? Nenhuma. E qual o custo? nada.

Ou melhor, podemos considerar o custo de tempo em pesquisar e aprender determinado assunto. Mas em um âmbito geral o custo é insignificante se comparado a época das enciclopédias e quando as universidades centralizavam todo o conhecimento relevante produzido pela sociedade. Hoje qualquer assunto está na internet, através de tutoriais, cursos gratuitos e textos informativos.

Com esse cenário é cabível pensar que precisamos educar as pessoas no sentido de lidar com os conteúdos que já estão disponíveis. Para que elas saibam…

We reach our interiority when we look for contact with our essence. It means muting the outer world. Even though there still noises around us, it is a big mistake to recognize every noise as valid information source or at least as worthy of absorption.

The job of filtering what we want for our innermost and let it come through our mind is individual. It has always been and will always be.

Despite the fact that are more information than we can handle its our intelectual job not only to filter it. Which is very passive. Our job is about…

Fernando Abolafio

I breath, I eat, I love and I code.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store