error ‘@testing-library/react’ should be listed in the project’s dependencies, not devDependencies

This is an ESLint error

This error comes from the import/no-extraneous-dependencies rule, which expects any module you import in non-test code to be in the regular dependencies section, not in the devDependencies.

To fix this issue, we need to configure ESLint to allow this import. If the file which is throwing this error is only used in tests, update the ESLint configuration file (.eslintrc.js) as follows

Difference between map and flatmap in javascript with examples.

map() in JavaScript :

  1. map() method creates a new Array by applying a function to each element of the original Array.
  2. map() returns a new Array of the Same Length.
  3. map() does not modify the original Array.

Example of returning an Array :

Example of returning nested Array Structure :

Example with null / undefined values in the Array :

flatMap() in JavaScript :

  1. flatMap() method first maps each element using a function, then flattens the result by one level.
  2. Applies a function like map()
  3. flattens one level deep of nesting.
  4. useful to remove null/undefined from Array.

Example of returning an Array like map() :

const array = [5, 10, 15, 20];
const newArray = array.flatMap(n => n * 2);
console.log(newArray);

Output :

[ 10, 20, 30, 40 ]

Example of nested structure into a flat Array :

Example with null / undefined values in the Array :

NOTE : flatMap() only flattens one level deep.

Recreating the dropped table using Prisma and PostgreSQL

Following command will do a soft reset

This command will drop all tables and Recreate Schema with correct column order.

After that, following command will recreate the migration for version control

Steps to Build Offline APK for Real Device – React Native

To test our React Native App in our phone, we can follow the following steps.

STEP 1 : Generate JS Bundle

Run the above command in your project root folder. This will pack your code into a static file.

STEP 2: Build the APK

navigate to android folder using this command in terminal.

Now build a debug APK using gradle

Now you can find the APK file in the following path

Now we can install this APK in our Android phone to test our App.

TypeError: cli.init is not a function – React Native

This error will come while running the following command.

This happens because react-native-cli is deprecated and not compatible with recent versions of node js. Especially from Node 18 + it throws this error.

To fix this issue first Uninstall react-native-cli using the following command.

use the official CLI as follows

Now it will install all the required packages to run the App.