<?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: Wesley_waka</title>
    <description>The latest articles on DEV Community by Wesley_waka (@wesleywaka).</description>
    <link>https://dev.to/wesleywaka</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%2F1119859%2F80211d34-e892-47c7-b357-74ed1deea928.jpeg</url>
      <title>DEV Community: Wesley_waka</title>
      <link>https://dev.to/wesleywaka</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/wesleywaka"/>
    <language>en</language>
    <item>
      <title>React Query - useQuery</title>
      <dc:creator>Wesley_waka</dc:creator>
      <pubDate>Thu, 27 Jul 2023 04:17:08 +0000</pubDate>
      <link>https://dev.to/wesleywaka/react-query-usequery-d04</link>
      <guid>https://dev.to/wesleywaka/react-query-usequery-d04</guid>
      <description>&lt;p&gt;Hey Folks,&lt;br&gt;
It's time to take a journey on &lt;a href="https://tanstack.com/query/latest"&gt;react query&lt;/a&gt;. Don't you know it? Perfect, you are in the right place 😁&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
What is React Query? React query is an npm library created by &lt;a href="https://twitter.com/i/flow/login?redirect_after_login=%2Ftannerlinsley"&gt;@TannerLinsley.&lt;/a&gt;&lt;br&gt;
It's a state manager for react that simplifies many tasks like handling the HTTP request state, saving data in the client to prevent many requests, sharing data in your application using hooks and so on.&lt;br&gt;
You'll discover more in this series about it, learn how to use it, and appreciate its simplicity in your react applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useQuery&lt;/strong&gt;&lt;br&gt;
The first core concept is useQuery. Through it, you can retrieve data from a source and handle all the states of this request in a very simple way.&lt;br&gt;
Let's see an example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useQuery } from '@tanstack/react-query';

const fetchTodos = async (): Promise&amp;lt;Todo[]&amp;gt; =&amp;gt; {
  const response = await fetch('api/tasks');
  if (!response.ok) {
    throw new ResponseError('Failed to fetch todos', response);
  }
  return await response.json();
};

export const useTodos = (): UseTodos =&amp;gt; {
  const {
    data: todos = [],
    isLoading,
    isFetching,
    error,
  } = useQuery(['todos'], fetchTodos, {
    refetchOnWindowFocus: false,
    retry: 2,
  });
...
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, you can see the essentials of useQuery.&lt;br&gt;
UseQuery is a react hook; it takes 3 params:&lt;/p&gt;

&lt;p&gt;The query key&lt;/p&gt;

&lt;p&gt;The query function&lt;/p&gt;

&lt;p&gt;The configurations&lt;/p&gt;

&lt;p&gt;Let's start with the first one. The query key is a key used by react query to identify your queries; through the key, react query is able to store the result and use it in different parts of the application. The key is used to identify the query, and with it you can also reset the query or change the value by code using the React Query Client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The query function&lt;/strong&gt; is the method used to retrieve data from a source (rest, graphQL, etc. etc.). It's simple; a function that returns a kind of data could be a simple function or, in most cases, a promise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configurations&lt;/strong&gt;, ok these are simple :) There are many possible options to run the query in different ways (amount of retries, when refreshing the data, how to cache the data and so on..)&lt;/p&gt;

&lt;p&gt;The result of this hook has three important objects instead&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;data&lt;/strong&gt;; this object contains the result of your query function. Please, pay attention that the data could be undefined too; this is because on the first call when the request is pending, data is not yet presented&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;isLoading&lt;/strong&gt;; this flag indicates when react query is loading data. There is also the isFetching flag, which is important if you are creating infinite scrolling. The isFetching flag indicates that there is a request pending, which is perfect if the app is asking for the next info&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;error&lt;/strong&gt;: this object contains the error if your request has a problem; using it, you can get the error and create a pretty info message for the user&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ok&lt;/strong&gt;, you have an idea of how useQuery works and what its potentialities are, but if you are more interested in it, you can watch the video below to learn more about it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/q2r2yoq5zaQ"&gt;Youtube&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ok, that's all! I'll get back to you with another react query feature soon.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this content.&lt;/p&gt;

&lt;p&gt;Bye Bye 👋&lt;/p&gt;

&lt;p&gt;p.s. you can find the code of the video &lt;a href="https://github.com/Puppo/learning-react-query/tree/01-queries"&gt;github repo&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How to setUp AuthO API in React</title>
      <dc:creator>Wesley_waka</dc:creator>
      <pubDate>Sun, 23 Jul 2023 06:34:47 +0000</pubDate>
      <link>https://dev.to/wesleywaka/how-to-setup-autho-api-in-react-client-side-11ed</link>
      <guid>https://dev.to/wesleywaka/how-to-setup-autho-api-in-react-client-side-11ed</guid>
      <description>&lt;p&gt;Are you a frontend developer,Without any backend programming knowledge which is responsible for authenticating your Users into your app.Maybe,you are a backend developer who is tired of debugging your Authentication MVC model.Here is a step to step tutorial with a few clicks to set you on the go.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is OAuth
&lt;/h2&gt;

&lt;p&gt;Auth0 is a cloud-based identity and access management (IAM) platform that offers authentication and authorization as a service. It provides developers with a set of tools and APIs to easily add secure authentication and authorization functionalities to their web and mobile applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  The key features of Auth0 include:
&lt;/h2&gt;

&lt;p&gt;-Authentication: Auth0 supports various authentication methods, such as social login (e.g., Google, Facebook, Twitter), username/password authentication, multi-factor authentication (MFA), and more. This allows developers to offer users multiple ways to log in to their applications securely.&lt;/p&gt;

&lt;p&gt;-Authorization: Auth0 provides a flexible and customizable authorization system that allows developers to define fine-grained access control policies for their resources. This helps ensure that users only have access to the resources they are authorized to use.&lt;/p&gt;

&lt;p&gt;-Single Sign-On (SSO): Auth0 enables single sign-on, allowing users to log in once and access multiple applications without the need to re-enter their credentials for each one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Developer-Friendly: Auth0 provides SDKs and libraries for various programming languages and platforms, making it developer-friendly and straightforward to integrate authentication and authorization functionalities into applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Steps to follow
&lt;/h2&gt;

&lt;p&gt;1.Create a new Account&lt;br&gt;
-Navigate to &lt;a href="https://auth0.com/signup?place=header&amp;amp;type=button&amp;amp;text=sign%20up"&gt;&lt;/a&gt;&lt;br&gt;
-Sign up if You do not have an already signed in account&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NYX6YIZ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ybyvhzbnmzkns3h8c9pg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NYX6YIZ7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ybyvhzbnmzkns3h8c9pg.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;br&gt;
-On success upon sign up or login You will be navigated to the user dashboard where you are responsible of managing your apps.&lt;/p&gt;

&lt;p&gt;2.Create an Application&lt;br&gt;
-In the user dashboard click on the create application in the get started section&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ty-wzu2d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eklt57357ooze1gycgtq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ty-wzu2d--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eklt57357ooze1gycgtq.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A pop-up will appear,enter the name of your app,beneath th name there are various options of application to create for the authentication.
-Since we are dealing with a frontend framework (React) choose SPWA(Single Page Web Page Application) option.
-On success You will be redirected to choose Your SPWA framework option,choose react&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TaNeN9Hr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/or75ej8w8ztoqfza3n9p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TaNeN9Hr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/or75ej8w8ztoqfza3n9p.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3.Auth settings &amp;amp; configuration&lt;/p&gt;

&lt;p&gt;-Confirm that your panel has been set up and navigate to settings &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TeJ0hF3r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7jb5tf0moy9vy9983ghx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TeJ0hF3r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7jb5tf0moy9vy9983ghx.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-In the settings section includes personal information about your API.&lt;/p&gt;

&lt;p&gt;4.App code configuration&lt;br&gt;
-Copy the clientId and Domain name mentioned in the settings panel safely since they are the essential information to gain access to our API.&lt;br&gt;
-In your React application run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i @auth0/auth0-react 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;responsible for installing package for authO provider&lt;br&gt;
-Back in your React code,make sure your app is wrapped with the authOprovider.&lt;br&gt;
-copy and paste your domain and clientId as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import { Auth0Provider } from '@auth0/auth0-react';

const root = ReactDOM.createRoot(document.getElementById('root'));
// dev-bgl7q1jcjwnen30i.us.auth0.com
// BB6LuOvArlkD9hjzUdOcGJhhwKtlIkWv
root.render(
    &amp;lt;Auth0Provider
        domain="dev-bgl7q1jcjwnen30i.us.auth0.com"
        clientId="BB6LuOvArlkD9hjzUdOcGJhhwKtlIkWv"
        authorizationParams={{
            redirect_uri: window.location.origin,
        }}
    &amp;gt;

         &amp;lt;App /&amp;gt;

    &amp;lt;/Auth0Provider&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5.Application properties&lt;br&gt;
-If you have a logo deployed you may switch the logo URL&lt;br&gt;
-Change the application type to Single Page Application&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uD1NXLAc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s78bbhdk0pz0up9uudma.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uD1NXLAc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s78bbhdk0pz0up9uudma.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;6.Setting up Your App URI's&lt;br&gt;
-Once you're done navigate to back to AuthO scroll down to Application URI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZnChtU1u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1m5dbqs9crbv1decdy12.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZnChtU1u--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1m5dbqs9crbv1decdy12.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-Copy and paste your deployed react web app,if deployed else &lt;br&gt;
copy and paste your localhost URL in each of the entries within the application URI.&lt;/p&gt;

&lt;p&gt;7.Confirmation&lt;br&gt;
-Once you are done scroll to the bottom of the page and click on save changes &lt;br&gt;
-Launch you your app with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;command and hopefully on Launch when you click on the login.You'll see a page similar to this one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--MlbaLqpX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8crfx6hzban97jy9wr8n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--MlbaLqpX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8crfx6hzban97jy9wr8n.png" alt="Image description" width="800" height="368"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope it was insightful don't forget to leave a thumb's Up&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
