<?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: Opeyemi Emmanuel Pcharles</title>
    <description>The latest articles on DEV Community by Opeyemi Emmanuel Pcharles (@pcharles).</description>
    <link>https://dev.to/pcharles</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%2F1977690%2F6dce99f7-741d-4eda-9d82-fee6111fc298.png</url>
      <title>DEV Community: Opeyemi Emmanuel Pcharles</title>
      <link>https://dev.to/pcharles</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pcharles"/>
    <language>en</language>
    <item>
      <title>Master the Usequery Method</title>
      <dc:creator>Opeyemi Emmanuel Pcharles</dc:creator>
      <pubDate>Thu, 27 Mar 2025 20:43:19 +0000</pubDate>
      <link>https://dev.to/pcharles/master-the-usequery-method-4h0f</link>
      <guid>https://dev.to/pcharles/master-the-usequery-method-4h0f</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/pcharles" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1977690%2F6dce99f7-741d-4eda-9d82-fee6111fc298.png" alt="pcharles"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/pcharles/mastering-api-calls-in-react-with-usequery-and-typescript-2lof" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Mastering API Calls in React with useQuery and TypeScript&lt;/h2&gt;
      &lt;h3&gt;Opeyemi Emmanuel Pcharles ・ Mar 27&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#mobile&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#typescript&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>programming</category>
      <category>mobile</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Mastering API Calls in React with useQuery and TypeScript</title>
      <dc:creator>Opeyemi Emmanuel Pcharles</dc:creator>
      <pubDate>Thu, 27 Mar 2025 17:34:00 +0000</pubDate>
      <link>https://dev.to/pcharles/mastering-api-calls-in-react-with-usequery-and-typescript-2lof</link>
      <guid>https://dev.to/pcharles/mastering-api-calls-in-react-with-usequery-and-typescript-2lof</guid>
      <description>&lt;p&gt;When building modern web and mobile applications, efficient API data fetching and caching are crucial for performance and user experience. The useQuery hook from React Query is a game-changer in simplifying API calls, improving caching, and handling states like loading and errors seamlessly. I'll explore why and how to use useQuery effectively with TypeScript.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Use useQuery for API Calls?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Traditionally, developers handle API calls using useEffect and local state management. However, this approach often leads to unnecessary re-fetching, complex state handling, and redundant code. Here’s why useQuery is a better alternative:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatic Caching – Fetch results are cached and reused, reducing redundant network calls.&lt;/li&gt;
&lt;li&gt;Auto Refetching – Stale data is refreshed automatically when necessary.&lt;/li&gt;
&lt;li&gt;Better State Management – Provides built-in states like isLoading, isError, and data.&lt;/li&gt;
&lt;li&gt;Optimistic Updates – Enhances UI responsiveness by pre-updating data before an API response.&lt;/li&gt;
&lt;li&gt;Background Syncing – Keeps data fresh in the background without blocking UI rendering.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Setting Up React Query in Your Project&lt;/strong&gt;&lt;br&gt;
First, install react-query and @tanstack/react-query in your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @tanstack/react-query
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, wrap your application with the QueryClientProvider in your main entry file e.g index/app.tsx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

const queryClient = new QueryClient();

ReactDOM.createRoot(document.getElementById('root')!).render(
  &amp;lt;QueryClientProvider client={queryClient}&amp;gt;
    &amp;lt;App /&amp;gt;
  &amp;lt;/QueryClientProvider&amp;gt;
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const getAllChains = async () =&amp;gt; {
  const response = await fetch('https://api.sampleapis.com/fakeapi/chains');
  if (!response.ok) {
    throw new Error('Network response was not ok');
  }
  return response.json();
};

export const useGetAllChains = () =&amp;gt; {
  return useQuery({
    queryKey: ['getAllChains'],
    queryFn: getAllChains,
    staleTime: 3600000, // Cache data for 1 hour
  });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;queryKey: ['getAllChains'] – Unique key to identify the query and manage caching.&lt;/li&gt;
&lt;li&gt;queryFn – The async function fetching data from the API.&lt;/li&gt;
&lt;li&gt;staleTime: 3600000 – Ensures data is not refetched for 1 hour&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using the Hook in a Component&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Now, let's consume this hook in a React component:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { useGetAllChains } from '../hooks/useGetAllChains';

const ChainList: React.FC = () =&amp;gt; {
  const { data, isLoading, isError } = useGetAllChains();

  if (isLoading) return &amp;lt;p&amp;gt;Loading chains...&amp;lt;/p&amp;gt;;
  if (isError) return &amp;lt;p&amp;gt;Error fetching chains.&amp;lt;/p&amp;gt;;

  return (
    &amp;lt;ul&amp;gt;
      {data?.map((chain) =&amp;gt; (
        &amp;lt;li key={chain.id}&amp;gt;{chain.name}&amp;lt;/li&amp;gt;
      ))}
    &amp;lt;/ul&amp;gt;
  );
};

export default ChainList;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Key Benefits:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;No manual state management – isLoading and isError handle API states automatically.&lt;/li&gt;
&lt;li&gt;Efficient caching – Prevents unnecessary API calls.&lt;/li&gt;
&lt;li&gt;Code reusability – The useGetAllChains hook can be used across multiple components.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using useQuery for API calls in React applications provides cleaner code, better caching, and improved performance. By leveraging React Query’s capabilities, you can optimize API data fetching, enhance user experience, and simplify state management.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>mobile</category>
      <category>typescript</category>
    </item>
    <item>
      <title>[web3 wallet connect]</title>
      <dc:creator>Opeyemi Emmanuel Pcharles</dc:creator>
      <pubDate>Wed, 26 Mar 2025 00:43:43 +0000</pubDate>
      <link>https://dev.to/pcharles/-4aa4</link>
      <guid>https://dev.to/pcharles/-4aa4</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/pcharles" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1977690%2F6dce99f7-741d-4eda-9d82-fee6111fc298.png" alt="pcharles"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/pcharles/smart-function-to-connect-a-wallet-and-sign-transactions-on-env-or-sol-via-phantom-5a54" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Smart Function to Connect a Wallet and Sign Transactions on EVM or SOL Via Phantom&lt;/h2&gt;
      &lt;h3&gt;Opeyemi Emmanuel Pcharles ・ Mar 25&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#programming&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#beginners&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Smart Function to Connect a Wallet and Sign Transactions on EVM or SOL Via Phantom</title>
      <dc:creator>Opeyemi Emmanuel Pcharles</dc:creator>
      <pubDate>Tue, 25 Mar 2025 23:00:00 +0000</pubDate>
      <link>https://dev.to/pcharles/smart-function-to-connect-a-wallet-and-sign-transactions-on-env-or-sol-via-phantom-5a54</link>
      <guid>https://dev.to/pcharles/smart-function-to-connect-a-wallet-and-sign-transactions-on-env-or-sol-via-phantom-5a54</guid>
      <description>&lt;p&gt;Phantom Wallet is one of the most popular wallets for interacting with the Solana blockchain. If you're building a dApp that requires users to connect their wallets and sign transactions, here's a smart way to achieve that using JavaScript or typescript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fwd2og1el5dr8gl074x7n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fwd2og1el5dr8gl074x7n.png" alt="Wallet connect" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connecting Phantom Wallet&lt;/p&gt;

&lt;p&gt;First, ensure the user has Phantom installed. Then, use the following function to connect&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function connectPhantom() {
  if (window.solana &amp;amp;&amp;amp; window.solana.isPhantom) {
    try {
      const response = await window.solana.connect();
      console.log("Connected with public key:", response.publicKey.toString());
      return response.publicKey;
    } catch (err) {
      console.error("Connection failed", err);
    }
  } else {
    console.error("Phantom wallet not found! Install it from https://phantom.app/");
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Signing a Transaction&lt;/p&gt;

&lt;p&gt;Once connected, you can create and sign a transaction using Phantom&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function signAndSendTransaction(transaction) {
  if (!window.solana || !window.solana.isPhantom) {
    console.error("Phantom wallet is not connected");
    return;
  }

  try {
    transaction.feePayer = window.solana.publicKey;
    transaction.recentBlockhash = (await connection.getRecentBlockhash()).blockhash;

    const signedTransaction = await window.solana.signTransaction(transaction);
    const signature = await connection.sendRawTransaction(signedTransaction.serialize());
    console.log("Transaction signature:", signature);
    return signature;
  } catch (error) {
    console.error("Transaction signing failed", error);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using the Functions with a Button&lt;/p&gt;

&lt;p&gt;To integrate these functions into your UI, you can use a simple button like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button id="connect-button"&amp;gt;Connect Wallet&amp;lt;/button&amp;gt;
&amp;lt;button id="sign-button"&amp;gt;Sign Transaction&amp;lt;/button&amp;gt;

&amp;lt;script&amp;gt;
document.getElementById("connect-button").addEventListener("click", async () =&amp;gt; {
  await connectPhantom();
});

document.getElementById("sign-button").addEventListener("click", async () =&amp;gt; {
  const transaction = new solanaWeb3.Transaction(); // Add instructions as needed
  await signAndSendTransaction(transaction);
});
&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function allows your dApp to connect with Phantom and sign transactions like swap, lend, stake or others , making it easy for users to interact with the Solana blockchain. Make sure to handle connection errors and display appropriate messages to improve user experience.&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to Disable Screenshot Capture in Your React Native Expo App</title>
      <dc:creator>Opeyemi Emmanuel Pcharles</dc:creator>
      <pubDate>Sun, 25 Aug 2024 20:04:41 +0000</pubDate>
      <link>https://dev.to/pcharles/how-to-disable-screenshot-capture-in-your-react-native-expo-app-39d7</link>
      <guid>https://dev.to/pcharles/how-to-disable-screenshot-capture-in-your-react-native-expo-app-39d7</guid>
      <description>&lt;p&gt;Privacy and security are critical for mobile applications, developers often need to ensure that sensitive information displayed in their apps cannot be easily captured through screenshots or screen recordings. While React Native Expo provides a powerful framework for building cross-platform apps, it doesn’t offer a built-in way to disable screenshot capture. However, you can achieve this by integrating native code into your Expo project.&lt;/p&gt;

&lt;p&gt;In this article, we’ll walk you through the steps to disable screenshot capture in your React Native Expo app for both Android&lt;/p&gt;

&lt;p&gt;Prerequisites&lt;br&gt;
Before starting, ensure you have the following:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Expo CLI installed and configured.&lt;/strong&gt;&lt;br&gt;
A basic understanding of React Native and Expo.&lt;br&gt;
Familiarity with integrating native modules into an Expo project.&lt;br&gt;
Why Disable Screenshot Capture?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Before diving into the technical details, let’s understand why you might want to disable screenshot capture in your app:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Security: Apps that display sensitive information, such as financial details, passwords, or personal data, should prevent unauthorized screenshots to avoid data leaks.&lt;br&gt;
User Privacy: Disabling screenshots can prevent unintended sharing of private content by users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Ejecting from Expo Managed Workflow&lt;/strong&gt;&lt;br&gt;
Expo’s managed workflow doesn’t support adding custom native code, so you’ll need to eject your Expo project to use the bare workflow. Here’s how you can do it:&lt;/p&gt;

&lt;p&gt;Run the following command in your project directory:&lt;br&gt;
expo eject&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Follow the prompts to configure your iOS and Android projects. This will generate the native iOS and Android directories required to add custom native code.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Implementing Native Code for Android&lt;/strong&gt;&lt;br&gt;
To disable screenshot capture in Android, you need to modify the MainActivity.java file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Open android/app/src/main/java/com/yourprojectname/MainActivity.java.&lt;br&gt;
Add the following code inside the onCreate method:&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import android.view.WindowManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Prevent screenshots in the app
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
                         WindowManager.LayoutParams.FLAG_SECURE);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code sets the &lt;code&gt;FLAG_SECURE&lt;/code&gt; flag on the window, preventing screenshots and screen recording within the app.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Testing Your Implementation&lt;/strong&gt;&lt;br&gt;
After implementing the native code, it’s essential to test the functionality:&lt;/p&gt;

&lt;p&gt;On Android, try taking a screenshot within the app; it should be blocked, and the user should receive a message indicating that screenshots are not allowed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Disabling screenshot capture in your React Native Expo app is crucial for protecting sensitive information. While Expo’s managed workflow doesn’t natively support this feature, by ejecting your app and adding custom native code, you can easily prevent screenshots and screen recordings.&lt;/p&gt;

&lt;p&gt;Keep in mind that ejecting from Expo’s managed workflow adds complexity to your project.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>tutorial</category>
      <category>mobile</category>
      <category>softwaredevelopment</category>
    </item>
  </channel>
</rss>
