<?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: Frank James</title>
    <description>The latest articles on DEV Community by Frank James (@frankdevstar).</description>
    <link>https://dev.to/frankdevstar</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%2F1039125%2F7a65159f-26ac-4ac9-8cc9-4265c91457a5.png</url>
      <title>DEV Community: Frank James</title>
      <link>https://dev.to/frankdevstar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/frankdevstar"/>
    <language>en</language>
    <item>
      <title>Using Camera in React Native</title>
      <dc:creator>Frank James</dc:creator>
      <pubDate>Tue, 07 Mar 2023 04:35:41 +0000</pubDate>
      <link>https://dev.to/frankdevstar/using-camera-in-react-native-5g2p</link>
      <guid>https://dev.to/frankdevstar/using-camera-in-react-native-5g2p</guid>
      <description>&lt;p&gt;React Native Camera is the go-to component when creating React Native apps that require the functionality of using the device’s camera. Maintained by the React Native community, this module has support for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Videos&lt;/li&gt;
&lt;li&gt;Photographs&lt;/li&gt;
&lt;li&gt;Face Detection&lt;/li&gt;
&lt;li&gt;Text Recognition&lt;/li&gt;
&lt;li&gt;Barcode Scanning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It also helps your React Native app to communicate with the native operating system using the device's hardware by implementing some helper methods.&lt;/p&gt;

&lt;p&gt;In this tutorial, let us build a simple QR code scanner app in React Native by implementing one of the functionalities this module supports, called Barcode scanning.&lt;/p&gt;

&lt;p&gt;For more information on RNCamera, please refer to its official documentation here. &lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Dependencies
&lt;/h2&gt;

&lt;p&gt;To begin, let us generate a React Native project by using the command below from a terminal window:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx react-native init qrCodeScannerApp

# navigate inside the directory once it is generated
cd qrCodeScannerApp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, you have to install some dependencies to use the RNCamera module. If you are on the latest React Native version, that is, a version above 60.x.x, run the following command from a terminal window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add react-native-camera
For iOS devices, you have to install the pods as shown below:

# after dependency installation
cd ios/

pod install

cd ..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Android users, there is no extra installation requirement at this point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Camera Permissions
&lt;/h2&gt;

&lt;p&gt;To access the device's hardware camera, a set of permissions have to be added. For iOS, please open the file ios/qrCodeScannerApp/Info.plist and add the following permissions:&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;!-- Required with iOS 10 and higher --&amp;gt;
&amp;lt;key&amp;gt;NSCameraUsageDescription&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;Your message to user when the camera is accessed for the first time&amp;lt;/string&amp;gt;

&amp;lt;!-- Required with iOS 11 and higher: include this only if you are planning to use the camera roll --&amp;gt;
&amp;lt;key&amp;gt;NSPhotoLibraryAddUsageDescription&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;Your message to user when the photo library is accessed for the first time&amp;lt;/string&amp;gt;

&amp;lt;!-- Include this only if you are planning to use the camera roll --&amp;gt;
&amp;lt;key&amp;gt;NSPhotoLibraryUsageDescription&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;Your message to user when the photo library is accessed for the first time&amp;lt;/string&amp;gt;

&amp;lt;!-- Include this only if you are planning to use the microphone for video recording --&amp;gt;
&amp;lt;key&amp;gt;NSMicrophoneUsageDescription&amp;lt;/key&amp;gt;
&amp;lt;string&amp;gt;Your message to user when the microphone is accessed for the first time&amp;lt;/string&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, to add permissions so that the app works correctly on an Android device, open the file android/app/src/main/AndroidManifest.xml and add the following:&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;!-- Required --&amp;gt;
&amp;lt;uses-permission android:name="android.permission.CAMERA" /&amp;gt;

&amp;lt;!-- Include this only if you are planning to use the camera roll --&amp;gt;
&amp;lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&amp;gt;
&amp;lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, open another file android/app/build.gradle and add the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;android {
 ...
 defaultConfig {
 ...
 // insert this line
 missingDimensionStrategy 'react-native-camera', 'general'
 }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it for the installation process for the OS platforms. From the next section, let us continue to build the app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the Camera in a React Native App
&lt;/h2&gt;

&lt;p&gt;In this section, let us first try and test the RNCamera module. Open the App.js file and start by adding the following import statements. Nothing fancy here. You just have to import the core React Native components such as View and Alert as well as RNCamera from react-native-camera.&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, { Component } from 'react'
import { StyleSheet, View, Alert } from 'react-native'
import { RNCamera } from 'react-native-camera'
Then, create a class component App that is going to render the JSX that uses a hardware camera on the device's screen. This going to be done by wrapping the RNCamera component inside a View.

class App extends Component {
  render() {
    return (
      &amp;lt;View style={styles.container}&amp;gt;
        &amp;lt;RNCamera
          style={{ flex: 1, alignItems: 'center' }}
          ref={ref =&amp;gt; {
            this.camera = ref
          }}
        /&amp;gt;
      &amp;lt;/View&amp;gt;
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'column',
    backgroundColor: 'black'
  }
})

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

&lt;/div&gt;



&lt;p&gt;After adding the above snippet, make sure you build the app for the OS you are using to test it. I am going to use a real Android device for testing.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
# for iOS
react-native run-ios

# for Android
react-native run-android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When testing on an Android device, please make sure that the device is connected via USB, and make sure that USB debugging is enabled as well before you run the previous build command from a terminal window.&lt;/p&gt;

&lt;p&gt;After the app has finished building and this process triggers the metro bundler, you are going to get a prompt asking for permission when the app runs for the first time.&lt;/p&gt;

&lt;p&gt;This means that the camera is working as expected and now you can leverage this to scan QR codes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading a QR Code Information
&lt;/h2&gt;

&lt;p&gt;To read the QR code information, you will have to make use of the prop onGoogleVisionBarcodesDetected. This prop, with the help of a helper method, can be used to evaluate the value of the scanned QR code.&lt;/p&gt;

&lt;p&gt;In the App.js file, start by modifying the RNCamera component as below.&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;RNCamera
  ref={ref =&amp;gt; {
    this.camera = ref
  }}
  style={styles.scanner}
  onGoogleVisionBarcodesDetected={this.barcodeRecognized}
/&amp;gt;
Add the corresponding styles for the Camera component in the previously defined StyleSheet object.

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'column',
    backgroundColor: 'black'
  },
  // add the following
  scanner: {
    flex: 1,
    justifyContent: 'flex-end',
    alignItems: 'center'
  }
})
Then, before the render method, add the helper method barcodeRecognized as well the state variable barcodes whose initial value is going to be an array.

state = {
  barcodes: []
}

barcodeRecognized = ({ barcodes }) =&amp;gt; {
  barcodes.forEach(barcode =&amp;gt; console.log(barcode.data))
  this.setState({ barcodes })
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above helper method is going to update the state variable barcodes that can be used to render the value of the QR code scanned using the RNCamera. Let us add two helper methods following the barcodeRecognized method. These helper methods are going to be responsible for displaying the information of the QR code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;renderBarcodes = () =&amp;gt; (
  &amp;lt;View&amp;gt;{this.state.barcodes.map(this.renderBarcode)}&amp;lt;/View&amp;gt;
)

renderBarcode = ({ data }) =&amp;gt;
  Alert.alert(
    'Scanned Data',
    data,
    [
      {
        text: 'Okay',
        onPress: () =&amp;gt; console.log('Okay Pressed'),
        style: 'cancel'
      }
    ],
    { cancelable: false }
  )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lastly, to render the Alert box, make sure you add the code below to modify the RNCamera component as below.&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;RNCamera
  ref={ref =&amp;gt; {
    this.camera = ref
  }}
  style={styles.scanner}
  onGoogleVisionBarcodesDetected={this.barcodeRecognized}&amp;gt;
  {this.renderBarcodes}
&amp;lt;/RNCamera&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Now, let us go back to the app and test it out.&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>webdev</category>
      <category>mobile</category>
    </item>
    <item>
      <title>How to use useMemo() in React JS?</title>
      <dc:creator>Frank James</dc:creator>
      <pubDate>Sun, 05 Mar 2023 20:20:34 +0000</pubDate>
      <link>https://dev.to/frankdevstar/how-to-use-usememo-in-react-js-4g3i</link>
      <guid>https://dev.to/frankdevstar/how-to-use-usememo-in-react-js-4g3i</guid>
      <description>&lt;h2&gt;
  
  
  What is useMemo, and How It Works in React?
&lt;/h2&gt;

&lt;p&gt;useMemo in React is essential react hook for improving the performance and speed of your application by caching the output in the computer memory and returning it when the same input is given again.&lt;/p&gt;

&lt;p&gt;So how does this hook works in ReactJs? Let’s use a real-life example to explain this concept. Assuming that your high school teacher asked you for the total number of students in your class, you counted the students and told him that it was 50. You wouldn’t need to do the counting again when he asks you the next day. All you need is to give him the same answer as yesterday unless some new students were added to your class; now you have to count or calculate again. This is how the React memo hook works.&lt;/p&gt;

&lt;p&gt;The React useMemo hook performs some calculations when requested and caches the result in the computer memory. Whenever the React memo hooks are asked to perform another operation with the same value, the old result will be returned without needing to waste computer resources calculating all over again.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Syntax
&lt;/h2&gt;

&lt;p&gt;The React hooks useMemo take two arguments in its parameter. These arguments are an array of dependencies and some functions whose output you want to cache. By default, the useMemo hook will execute the function you passed as an argument after the initial render.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use the useMemo() React Hook 
&lt;/h2&gt;

&lt;p&gt;You can start using the useMemo hook in your next React project by following the steps below:&lt;/p&gt;

&lt;h2&gt;
  
  
  useMemo() Hook
&lt;/h2&gt;

&lt;p&gt;Step 1: Import the hook from the React library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useMemo } from "react";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Compute with the useMemo hook:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const memodVal = useMemo(() =&amp;gt; {/* function */}, [/* Dependencies */]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Render the useMemo result on screen:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div className="App"&amp;gt;{memodVal}&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  useMemo() — an Example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./styles.css";
import { useState, useMemo } from "react";


export default function App() {
  const [grade, setGrade] = useState(5);
  const countPopulation = ((grade) =&amp;gt; {
    return grade ** 2;
  });


  const memoizedVal = useMemo(() =&amp;gt; countPopulation(grade), []);

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;p&amp;gt;Current Grade: {grade}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Current Population: {memoizedVal}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  useMemo() vs useCallback()
&lt;/h2&gt;

&lt;p&gt; &lt;br&gt;
The useMemo hook and the react useCallback hook are very similar. Both use memoization caching techniques; however, the main difference between these two hooks is that, while the useCallback hook allows you to memoize the entire function, the useMemo hook only will enable you to memoize the output of functions.&lt;/p&gt;

&lt;p&gt;Enroll in the best Web Development courses to strengthen your career in web development.   &lt;/p&gt;

&lt;p&gt;For instance, this is how closely related useMemo is to useCallback…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./styles.css";
import { useState, useMemo } from "react";
export default function App() {
  const [grade, setGrade] = useState(3);
  const countPopulation = (grade) =&amp;gt; grade ** 2;
  const memoizedVal = useMemo(() =&amp;gt; countPopulation(grade), [grade]);

  
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;RenderVal grade={grade} val={memoizedVal} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
const RenderVal = ({ grade, val }) =&amp;gt; {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;p&amp;gt;Current Grade: {grade}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;
        Current Population: {' '}
        {typeof val === 'function' ? val() : val}
      &amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;Now, let’s see how to use it along with the react useCallback hook…&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "./styles.css";
import { useState, useCallback  } from "react";
export default function App() {
  const [grade, setGrade] = useState(3);
  const countPopulation = countPopulation(grade), [grade]);
  const memoizedCallback = useCallback (() =&amp;gt; countPopulation(grade), [grade]);

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;RenderVal grade={grade} val={memoizedCallback} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
const RenderVal = ({ grade, val }) =&amp;gt; {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;p&amp;gt;Current Grade: {grade}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;
        Current Population: {' '}
        {typeof val === 'function' ? val() : val}
      &amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use Memoization with Care 
&lt;/h2&gt;

&lt;p&gt;While the useMemo hook can improve your app's performance, you should also run some scans on your codebase to determine which operations must be memoized. Only after the scan should you decide if memoization is worthwhile. When memoization is used inappropriately, it can lead to other performance issues.&lt;/p&gt;

&lt;p&gt;Check out  the App development course online by KnowledgeHut and get training in various fields of App development.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to Run the useMemo() React Hook 
&lt;/h2&gt;

&lt;p&gt;There are three conditions where useMemo can be the best option for you, and they are discussed below:&lt;/p&gt;

&lt;h2&gt;
  
  
  Only After Initial Render 
&lt;/h2&gt;

&lt;p&gt;Going by this first option, the hook will run once and never again after the initial render. The function will not be executed again even if something causes the component to re-render. Instead, it will return the function's memoized output. This will be repeated for each subsequent re-render.&lt;/p&gt;

&lt;p&gt;If this option is what you want to do, then the dependency array must be left empty. This means that the useMemo hook should not be watching any values. It should always return the previously memorized or cached output.&lt;/p&gt;

&lt;p&gt;See the implementation 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 "./styles.css";
import { useState, useMemo, useEffect  } from "react";
export default function App() {
  const [grade, setGrade] = useState(3);
  const countPopulation = (grade) =&amp;gt; {
    return grade ** 2;
  };
  const memoizedVal = useMemo (
    () =&amp;gt; countPopulation(grade),
    [/* Nothing to watch for */]
  );


  useEffect(() =&amp;gt; {
    console.log(`Initial Memoized Value is: ${memoizedVal}`);
  }, [memoizedVal])
  
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;RenderVal grade={grade} val={memoizedVal} /&amp;gt;
      &amp;lt;button 
        onClick={
          () =&amp;gt; setGrade(prevGrade =&amp;gt; prevGrade += 1)
        }&amp;gt;Increase Grade&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
const RenderVal = ({ grade, val }) =&amp;gt; {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;p&amp;gt;Current Grade: {grade}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Current Population: {val}&amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Only When Dependency Changes 
&lt;/h2&gt;

&lt;p&gt;When the specific value changes, the second option is to run useMemo and execute the function you passed. This will come in handy if the function you passed as an argument accepts a value from the outside world. If this outside value changes, you would want to recalculate the output to ensure it is correct.&lt;/p&gt;

&lt;p&gt;You must specify the value you want to "watch" as one of the dependencies to accomplish this. useMemo will then monitor this value and execute the function you specified whenever the monitored value changes. If it does not change, useMemo will return the memoized value, which is the value from the most recent execution.&lt;/p&gt;

&lt;p&gt;See the code block 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 "./styles.css";
import { useState, useMemo, useEffect } from "react";
export default function App() {
  const [grade, setGrade] = useState(3);
  const countPopulation = (grade) =&amp;gt; {
    return grade ** 2;
  };
  const memoizedVal = useMemo(() =&amp;gt; countPopulation(grade), [grade]);
  useEffect(() =&amp;gt; {
    console.log(`Initial Memoized Value is: ${memoizedVal}`);
  }, [memoizedVal]);
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;RenderVal grade={grade} val={memoizedVal} /&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setGrade((prevGrade) =&amp;gt; (prevGrade += 1))}&amp;gt;
        Increase Grade
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
const RenderVal = ({ grade, val }) =&amp;gt; {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;p&amp;gt;Current Grade: {grade}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Current Population: {val}&amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  How To Use React useMemo() Hook API Reference In React Native
&lt;/h2&gt;

&lt;p&gt;From the image above, you can see that for every click of the increase grade button, the useMemo hook does some recalculation because it has a watch value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;After Every Re-render 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final option is to instruct useMemo to re-run the function you specified on each re-render. Doing this will nullify the sole purpose of using a useMemo hook. It is meaningless to use a useMemo to memoize something only to clear it out. Nevertheless, because this is an option, we must showcase it. A little warning to you, this option is a complete waste of time and is not recommended for use.&lt;/p&gt;

&lt;p&gt;Let's say this is your only option, which is not true. You must remove the dependency array to persuade the useMemo hook to run on every render. The only argument required this time is the function.&lt;/p&gt;

&lt;p&gt;Let’s see the code snippet 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 "./styles.css";
import { useState, useMemo, useEffect } from "react";
export default function App() {
  const [grade, setGrade] = useState(3);
  const countPopulation = (grade) =&amp;gt; {
    return grade ** 2;
  };
  const memoizedVal = useMemo(() =&amp;gt; countPopulation(grade));
  useEffect(() =&amp;gt; {
    console.log(`Initial Memoized Value is: ${memoizedVal}`);
  }, [memoizedVal]);
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;RenderVal grade={grade} val={memoizedVal} /&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; setGrade((prevGrade) =&amp;gt; (prevGrade += 1))}&amp;gt;
        Increase Grade
      &amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
const RenderVal = ({ grade, val }) =&amp;gt; {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;p&amp;gt;Current Grade: {grade}&amp;lt;/p&amp;gt;
      &amp;lt;p&amp;gt;Current Population: {val}&amp;lt;/p&amp;gt;
    &amp;lt;/&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How To Use React useMemo() Hook API Reference In React Native
&lt;/h2&gt;

&lt;p&gt;From the example above, the useMemo kept re-computing on every re-render aborting the real purpose of using the useMemo hook since we removed the dependency array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use useMemo Hook with Caution 
&lt;/h2&gt;

&lt;p&gt;Optimization and performance are vital ingredients for developing a scalable and production-ready application. But by pursuing performance and optimization too much, you could end up introducing more problems than solutions in your code. You can easily overuse the React useMemo hook, that is why you must consider your options carefully before deciding to use the useMemo hook. Keep in mind that using the hook often adds some overhead, that is, the hook introduces new complex logic that must be considered.&lt;/p&gt;

&lt;p&gt;It can also cause new performance issues that you didn't expect. When you memoize something, it is saved in your computer memory. This provides more room for the CPU to process data faster. However, resources are still being used, for instance, memory is used more for caching your data. The only difference is the type of resource it consumes.&lt;/p&gt;

&lt;p&gt;Finally, do not create side-effects with functions passed to the useMemo hook. Side effects should be implemented within the useEffect hook. Additionally, do not use useMemo to update React state values. This is also a side effect, but it is worth mentioning. Use useMemo only for what was designed for memoizing and caching output values. To stay abreast of the latest react dev tools, visit top 12 react developer tools - extensions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion 
&lt;/h2&gt;

&lt;p&gt;That's much important information to take in in one tutorial. I hope this tutorial has helped you better understand performance optimization in ReactJs.&lt;/p&gt;

&lt;p&gt;The React useMemo hook can be helpful when looking for ways to improve the performance of your React applications. It can help you optimize costly computations by memorizing their output and re-running them only when necessary.&lt;/p&gt;

&lt;p&gt;If you enjoyed this tutorial, consider learning from our ecosystem; check out the KnowledgeHut React Native training.&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to build Web3 in Algorand Blockchain</title>
      <dc:creator>Frank James</dc:creator>
      <pubDate>Sun, 05 Mar 2023 20:06:11 +0000</pubDate>
      <link>https://dev.to/frankdevstar/integrate-web3-of-algorand-blockchain-4dcj</link>
      <guid>https://dev.to/frankdevstar/integrate-web3-of-algorand-blockchain-4dcj</guid>
      <description>&lt;p&gt;While using the Web3Auth Web SDK for a non EVM chain like Algorand you get a standard provider from which you can get the private key of the user. Using this private key, you can use the corresponding libraries of the blockchain to make blockchain calls like getting user's account, fetch balance, sign transaction, send transaction, read from and write to the smart contract, etc. We have highlighted a few methods here for getting you started quickly on that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initializing Provider
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Web3Auth } from "@web3auth/modal";
import { OpenloginAdapter } from "@web3auth/openlogin-adapter";

const web3auth = new Web3Auth({
  clientId: "YOUR_WEB3AUTH_CLIENT_ID", // get it from Web3Auth Dashboard
  web3AuthNetwork: "cyan",
  chainConfig: {
    chainNamespace: "other", // for all non EVM and SOLANA chains, use "other"
  },
});

// "other" is supported through @web3auth/openlogin-adapter package.
const openloginAdapter = new OpenloginAdapter({
  adapterSettings: {
    uxMode: "popup",
  },
});
web3auth.configureAdapter(openloginAdapter);

await web3auth.initModal();

const web3authProvider = web3auth.connect(); // web3auth.provider
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Get User Info
&lt;/h2&gt;

&lt;p&gt;Once logged in, Web3Auth instance returns you some information about your logged in user. This is fetched directly from the JWT token and Web3Auth doesn't store this info anywhere. Hence, this information in available in social logins only after the user has logged into your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const user = await web3auth.getUserInfo(); // web3auth instance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Get Account and KeyPair
&lt;/h2&gt;

&lt;p&gt;Once a user logs in, the Web3Auth SDK returns a provider. Since Web3Auth doesn't have a native provider for Algorand, we need to directly use the private key to make the RPC calls.&lt;/p&gt;

&lt;p&gt;Using the function, web3auth.provider.request({method: "private_key"}) from Web3Auth provider, the application can have access to the user's private key. However, we cannot use this key with Algorand specific signing functions, hence, we first derive the Algorand Key using the getAlgorandKeyPair() function.&lt;/p&gt;

&lt;p&gt;On the underhood, it uses the algosdk.secretKeyToMnemonic() function, where we need to pass the Buffer.from(privateKey, "hex"), ie. the hexadecimal to Uint8Array converted private key. We get a mnemonic seed phrase which can be used to derive the keypair using the algosdk.mnemonicToSecretKey(), this returns a keypair. We can use the returned private key pair from this and use on Algorand transactions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { SafeEventEmitterProvider } from "@web3auth/base";
import algosdk from "algosdk";


/*
  Use code from the above Initializing Provider here
*/

// web3authProvider is web3auth.provider from above
const privateKey = await web3authProvider.request({ method: "private_key" });

// derive the Algorand Key Pair from the private key
var passphrase = algosdk.secretKeyToMnemonic(Buffer.from(privateKey, "hex"));
var keyPair = algosdk.mnemonicToSecretKey(passphrase);

// keyPair.addr is the account address.
const account = keyPair.addr;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Get Balance
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { SafeEventEmitterProvider } from "@web3auth/base";
import algosdk from "algosdk";

/*
  Use code from the above Initializing Provider here
*/

// web3authProvider is web3auth.provider from above
const privateKey = await web3authProvider.request({ method: "private_key" });

// derive the Algorand Key Pair from the private key
var passphrase = algosdk.secretKeyToMnemonic(Buffer.from(privateKey, "hex"));
var keyPair = algosdk.mnemonicToSecretKey(passphrase);

// keyPair.addr is the account address.
const account = keyPair.addr;

// Making a connection to the Algorand TestNet
const algodToken = {
  "x-api-key": "YOUR_ALGOD_API_KEY",
};
const algodServer = "https://testnet-algorand.api.purestake.io/ps2"; // for testnet
const algodPort = "";
const algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);
const balance = await client.accountInformation(keyPair.addr).do();

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Send Transaction
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { SafeEventEmitterProvider } from "@web3auth/base";
import algosdk from "algosdk";

/*
  Use code from the above Initializing Provider here
*/

// web3authProvider is web3auth.provider from above
const privateKey = await web3authProvider.request({ method: "private_key" });

// derive the Algorand Key Pair from the private key
var passphrase = algosdk.secretKeyToMnemonic(Buffer.from(privateKey, "hex"));
var keyPair = algosdk.mnemonicToSecretKey(passphrase);

// keyPair.addr is the account address.
const account = keyPair.addr;

// Making a connection to the Algorand TestNet
const algodToken = {
  "x-api-key": "YOUR_ALGOD_API_KEY",
};
const algodServer = "https://testnet-algorand.api.purestake.io/ps2"; // for testnet
const algodPort = "";
const algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);

// Creating the transaction

const params = await client.getTransactionParams().do();
const enc = new TextEncoder();
const message = enc.encode("Web3Auth says hello!");

// You need to have some funds in your account to send a transaction
// You can get some testnet funds here: https://bank.testnet.algorand.network/

const txn = algosdk.makePaymentTxnWithSuggestedParams(
  keyPair.addr, // sender
  keyPair.addr, // receiver
  1000,
  undefined,
  message,
  params
);
let signedTxn = algosdk.signTransaction(txn, keyPair.sk);

const txHash = await client.sendRawTransaction(signedTxn.blob).do();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Sign Message
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { SafeEventEmitterProvider } from "@web3auth/base";
import algosdk from "algosdk";

/*
  Use code from the above Initializing Provider here
*/

// web3authProvider is web3auth.provider from above
const privateKey = await web3authProvider.request({ method: "private_key" });

// derive the Algorand Key Pair from the private key
var passphrase = algosdk.secretKeyToMnemonic(Buffer.from(privateKey, "hex"));
var keyPair = algosdk.mnemonicToSecretKey(passphrase);

// keyPair.addr is the account address.
const account = keyPair.addr;

// Making a connection to the Algorand TestNet

const algodToken = {
  "x-api-key": "YOUR_ALGOD_API_KEY",
};
const algodServer = "https://testnet-algorand.api.purestake.io/ps2"; // for testnet
const algodPort = "";
const algodClient = new algosdk.Algodv2(algodToken, algodServer, algodPort);

// Generating the message to sign

const params = await client.getTransactionParams().do();
const enc = new TextEncoder();
const message = enc.encode("Web3Auth says hello!");
const txn = algosdk.makePaymentTxnWithSuggestedParams(keyPair.addr, keyPair.addr, 0, undefined, message, params);
let signedTxn = algosdk.signTransaction(txn, keyPair.sk);
let txId = signedTxn.txID;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>blockchain</category>
      <category>javascript</category>
      <category>web3</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>The Differences between React and Angular</title>
      <dc:creator>Frank James</dc:creator>
      <pubDate>Sun, 05 Mar 2023 19:43:33 +0000</pubDate>
      <link>https://dev.to/frankdevstar/react-vs-angular-2nn</link>
      <guid>https://dev.to/frankdevstar/react-vs-angular-2nn</guid>
      <description>&lt;h2&gt;
  
  
  What is React JS?
&lt;/h2&gt;

&lt;p&gt;React is a JavaScript library developed by Facebook which allows you to build UI components. It facilitates the creation of interactive User Interfaces. It also makes the code easier to understand and launch. React Java Script framework uses server-side rendering to provide a flexible, performance-oriented solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Angular?
&lt;/h2&gt;

&lt;p&gt;Angular is a structural framework for developing dynamic web apps. It allows developers to use HTML as a template language and allows HTML’s syntax to express the application’s components briefly and clearly.&lt;/p&gt;

&lt;p&gt;It is a fully featured JavaScript framework that helps developing dynamic, single page web apps. It also supports the (MVC) programming structure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features of React
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Allows you to use 3rd party libraries&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Time-Saving&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Simplicity and Composable&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fully supported by Facebook.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Better user experience and very fast performance.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Faster Development&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Code Stability with One-directional data binding&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;React Components&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Key Features of Angular
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Built-in support for AJAX, HTTP, and Observables&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Large community support&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consistent with technology&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Typescript offers efficiency&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cleaner and crisp Coding&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enhanced support for error handling&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Seamless updates using Angular CLI&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Forms and validation&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shadow DOM / local CSS&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;UI and Business Logic Separation&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Advantages of React
&lt;/h2&gt;

&lt;p&gt;Here, are pros/benefits of using React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Easy to learn because of its simple Design&lt;/li&gt;
&lt;li&gt;The HTML-like syntax for which allows templating, and highly detailed documentation.&lt;/li&gt;
&lt;li&gt;Developers can spend more time writing modern JavaScript, and less time worrying about the framework-specific code.&lt;/li&gt;
&lt;li&gt;Enhance support for server-side rendering, making it a robust framework for content-focused applications.&lt;/li&gt;
&lt;li&gt;Migrating between versions is in React.&lt;/li&gt;
&lt;li&gt;Facebook offers “codemod” feature to automate much of the process.&lt;/li&gt;
&lt;li&gt;Skills learned in React can be applied to Native development.&lt;/li&gt;
&lt;li&gt;When you combine with ES6/7, ReactJS is perfect for managing heavy loads with relative ease.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Advantages of Angular
&lt;/h2&gt;

&lt;p&gt;Here, are pros/benefits of using Angular:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Offers clean code development&lt;/li&gt;
&lt;li&gt;Higher Performance&lt;/li&gt;
&lt;li&gt;Material Design-like Interface&lt;/li&gt;
&lt;li&gt;An angular framework can take care of routing which means moving from one view to another is easy&lt;/li&gt;
&lt;li&gt;Seamless Updates using Angular CLI&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of React
&lt;/h2&gt;

&lt;p&gt;Here, are cons/problems of using React:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Integrating Reacts in the traditional MVC framework like Rail requires complex configuration.&lt;/li&gt;
&lt;li&gt;ReactJS would require the users to have in-depth knowledge with respect to the integration of user interface into M VC framework.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Disadvantages of Angular
&lt;/h2&gt;

&lt;p&gt;Here, are cons/problems of using Angular:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An angular feature can be confusing for newcomers.&lt;/li&gt;
&lt;li&gt;The documentation on the official Angular site is difficult to understand&lt;/li&gt;
&lt;li&gt;Steep learning curve&lt;/li&gt;
&lt;li&gt;Scopes are hard to debug Limited Routing.&lt;/li&gt;
&lt;li&gt;There are so many versions of Angular&lt;/li&gt;
&lt;li&gt;SEO capabilities are limited&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Which is Better?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Both React and AngularJS are great options with respect to single page applications. However, both of them are also entirely different instruments. There might be statements like React is better than Angular or also vice versa.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whatever may be your perception of the discussion about React Vs. AngularJS, you need to make choices based on your, requirement of functionality and usability.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
