ReactNative & EXOP Error iOS Bundling failed 6ms Unable to resolve module

I am learning React Native and Expo. I trying to build an application that enables the user to log in using the phone number I have an issue “iOS Bundling failed 6ms Unable to resolve module ./screens/Phone Auth form ..”

I have been trying for almost a while to find a way to log in via the mobile number through Expo and React Native, but I have not found useful resources.
In all my attempts, many problems appear. I have tried several methods. Can I win from using the registration feature via the phone number?

App.js

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import PhoneAuth from './screens/PhoneAuth';
export default function App() {
  return (
    <View style={styles.container}>
      <PhoneAuth/>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

PhoneAuth.js

 import React, { useRef, useState } from 'react';
import { TouchableOpacity, Text, TextInput, View } from 'react-native';
import { FirebaseRecaptchaVerifierModal } from 'expo-firebase-recaptcha';
import Constants from 'expo-constants';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/firestore";
// other services is needed
// import styles from './styles';
const PhoneAuth = () => {
 const [phoneNumber, setPhoneNumber] = useState('');
  const [code, setCode] = useState('');
  const [verificationId, setVerificationId] = useState(null);
  const recaptchaVerifier = useRef(null);
   const sendVerification = () => {
    const phoneProvider = new firebase.auth.PhoneAuthProvider();
    phoneProvider
      .verifyPhoneNumber(phoneNumber, recaptchaVerifier.current)
      .then(setVerificationId);
  };

  const confirmCode = () => {
    const credential = firebase.auth.PhoneAuthProvider.credential(
      verificationId,
      code
    );
    firebase
      .auth()
      .signInWithCredential(credential)
      .then((result) => {
        console.log(result);
      });
  };
    return (
        <KeyboardAwareScrollView contentContainerStyle={styles.container}>
      <View>
        <FirebaseRecaptchaVerifierModal
          ref={recaptchaVerifier}
          firebaseConfig={Constants.manifest.extra.firebase}
        />
        <TextInput
          placeholder="Phone Number"
          onChangeText={setPhoneNumber}
          keyboardType="phone-pad"
          autoCompleteType="tel"
          style={styles.textInput}
        />
        <TouchableOpacity
          style={styles.sendVerification}
          onPress={sendVerification}
        >
          <Text style={styles.buttonText}>Send Verification</Text>
        </TouchableOpacity>
        <TextInput
          placeholder="Confirmation Code"
          onChangeText={setCode}
          keyboardType="number-pad"
          style={styles.textInput}
        />
        <TouchableOpacity style={styles.sendCode} onPress={confirmCode}>
          <Text style={styles.buttonText}>Send Verification</Text>
        </TouchableOpacity>
      </View>
    </KeyboardAwareScrollView>
    )
}


export default PhoneAuth;

not entering special characters on user input

I have an input field where i am trying to block the special characters [dot, hiphen, space comma and e] so that user can’t enter this special characters on both mobile and chrome.

export default function App() {
  const handleInput = (event) => {
    event.target.value = event.target.value.replace(/[e.- ]/g, "");
  };

  return (
    <div className="App">
      <input type="number" onInput={handleInput} />
    </div>
  );
}

Sandbox

Facing two issues on this, one is (999.) I am able to enter dot in between numbers, also when I enter some numbers and type hiphen then its clearing all the numbers (999-) => ().

How can I stop this two behaviour so that user can enter only 0-9 digits

Getting error While Printing the value of Select box in console with ReactJS

Hello i am new in ReactJS and I was making a Serial number generator which use the value of Select box and print that whole value in console in this code I Was trying to take the value of “Model” + then the value of “voltage” + unit + the last two digit of year + 000 + and in the last if the same two model is present so the last number will be 3 While running the code i got this error.

Line 18:4: ‘output1’ is not defined no-undef Line 20:13:
‘output4’ is not defined no-undef Line 23:13: ‘output7’ is not
defined no-undef Line 25:13: ‘e’ is not defined no-undef
Line 26:11: ‘model’ is not defined no-undef Line 26:17: ‘e’ is
not defined no-undef Line 26:27: ‘e’ is not defined
no-undef Line 37:45: ‘model’ is not defined no-undef

I don’t understand How to handle this Problem Can anyone Please help me with this.
This is my code

import React from "react";
import "./App.css";
import firebase from "./firebase";
// import { getDatabase, ref, child, get } from "firebase/database";
function App() {
  var app = firebase.database();
  var deviceref = app.ref("/");

  let serial = "";

  function getOption() {
    serial = "";
    output1 = document.querySelector("#Model").value;

    output4 = document.querySelector("#Voltage").value;

    output7 = document.getElementById("unit").value;

    e = document.querySelector("#Model");
    model = e.options[e.selectedIndex].text;

    var myDate = new Date();
    var year = myDate.getFullYear();
    var twoDigitYear = year.toString().substr(-2);
    console.log(twoDigitYear);

    deviceref
      .orderByChild("Model")
      .equalTo(model)
      .once("value", function (snapshot) {
        console.log(snapshot.val());

        var text = "";
        var machines = snapshot.val();

        if (machines == null) {
          var len = 0;
        } else {
          var len = Object.keys(machines).length;
        }

        let max = parseInt(len) + parseInt(output7);
        for (var i = len + 1; i <= max; i++) {
          value = ("000" + i).slice(-4);
          serial = output1 + output4 + twoDigitYear + value;

          console.log(serial);

          app.ref(serial).set({
            Model: model,
          });
          text += serial + "<br>";
        }
        document.getElementById("output").innerHTML = text;
      });
    alert("Serail No. Generated Successfully ");
    console.log("Serail No. Generated Successfully");
  }
  return (
    <>
      <main>
        <section class='container serial-container'>
          <img src='assets/images/55k-logo.png' alt='logo' />
          <br />
          <fieldset style={{ position: "center" }}>
            <div id='generator'>
              <b>Generate Unique Serial No. For New Machines</b> <br />
              <br />
              <p>
                Model:
                <select id='Model'>
                  <option>--</option>

                  <option value='07D092'>POD +</option>
                  <option value='15012'>36K-wide</option>
                  <option value='18011'>55K-wide</option>
                  <option value='19011'>Agri </option>
                  <option value='19D011'>55k plus</option>
                  <option value='20051'>180K</option>
                  <option value='04081'>365K</option>
                  <option value='07092'>07M</option>
                  <option value='21051'>Air to Water Rig</option>
                </select>
              </p>
              <p>
                Voltage:
                <select id='Voltage'>
                  <option>--</option>
                  <option value='1'>220V,50Hz,single phase</option>
                  <option value='2'>220V,60Hz,single phase </option>
                  <option value='3'>440V,50/60Hz,three phase </option>
                </select>
              </p>
              <p>
                Quantity:
                <input type='text' id='unit' />
              </p>
              Generated Unique Serial Numbers are:
              <p id='output'></p>
              <p>
                <button onclick={getOption()}>Generate</button>
              </p>
            </div>
          </fieldset>
        </section>
      </main>
    </>
  );
}

export default App;

input event with if condition

I use eventlistener to detect the rows in textarea, but when I press backspace the if condition doesn’t work. How can I improve this?

$('textarea').on('input', function() {
  // Get the scroll height of the textarea
  let taHeight = $('textarea').scrollHeight;
  let numberOfLines = Math.floor(taHeight / 16);
  height(numberOfLines);

})

function height(numberOfLines) {
  console.log(numberOfLines);
  if (numberOfLines == 2) {
    $('textarea').removeClass('row-2 row-3').addClass('row-2');
  } else if (numberOfLines == 3) {
    $('textarea').removeClass('row-2 row-3').addClass('row-3');
  } else {
    $('textarea').removeClass('row-2 row-3');
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<textarea></textarea>

How to retrieve some data from API and use it in all the pages of a NexJS application before rendering on client side?

I have a NextJS application where I have a home page (index.js) and two other pages About(about.js) & Contact Us(contact.js).

I have created a BaseLayour.js file with is wrapping NextJS’s MyApp component in _app.js file.

import React from "react";

import BaseLayout from "../layouts/BaseLayout";

function MyApp(props) {
  const { Component, pageProps } = props;

  return (
    <BaseLayout>
      <Component {...pageProps} />
    </BaseLayout>
  );
}

export default MyApp;

This BaseLayout component looks like this –

import React from "react";

import SEO from "../components/SEO";
import Header from "../components/Header";
import Footer from "../components/Footer";

function BaseLayout(props) {
  const { children } = props;

  return (
    <div>
      <SEO />
      <Header />
      {children}
      <Footer />
    </div>
  );
}

export default BaseLayout;

As you can see above in the BaseLayout file, there is an SEO component (React). It contains some common metadata for all the pages. I have an API(api/getmetadata/) that delivers all the metadata in JSON format.

This metadata is supposed to load on the server-side so that the page will be optimized for SEO.

How can we call the API in order to retrieve the data on each request but only on the server-side?

What I have tried till now –

  1. Tried calling API in the SEO component itself, but it is not running on the server-side as it is just a React component.
  2. Tried creating a React context, and called the API from SEO/BaseLayout components, the API call is still not being made from the server-side.
  3. Tried using getServerSideProps in the index.js page to call the API and retrieve the data, which worked perfectly, but the problem is we need to share the data between all the pages, not just the index.js home page.

Any help will be appreciated, If we can somehow make the API call and retrieve the data in the SEO component, it will solve our problem.

Thank you in advance guys.

How to add another item to function with javascript?

I have my website that shows the country list and when you click it you see the flag and sub region. If I wanted to add more information from the api how would I add it to the function? For example if I wanted to add the time zones and region. If I wanted to just keep adding them how would I write them into the code? jsfiddle

  xhttp.open("GET", "https://restcountries.com/v2/all", true);
    xhttp.send();
   
function clickMe(index) {
     //search and remove all image tags already inserted
  document.querySelectorAll('#list img').forEach(
    function(item) {
      item.remove();
  });
     //search and remove all div1 tags already inserted
     document.querySelectorAll('#list div1').forEach(
    function(item) {
      item.remove();
  });
     //create flag image on website
        li = document.getElementById(index);
        img = document.createElement("img")
        img.src = respJSON[index].flag;
        li.append(img);      
        //create subregion text on website   
        let div = document.createElement("div1");
        div.innerText = respJSON[index].subregion;
        li.append(div);
} ```

ask user to write file name before downloading txt file in angular

I am trying to download content in a txt file. belwo is the sample code

download() {
let content = "Sample text";
saveAs(new Blob([content], { type: 'text/plain'}), 'sample.txt');

I am using file-saver lib to downlaod the content.
all works fine but i need to open the browser popup where user can write/override the file name before downloading it.

Any help here will be highly appreciated.

React node js contact form error 404 in production

I’ve made a contact form for my react app that works on localhost but once I deploy it doesn’t work anymore. Been trying different url for post, with or without port but each time it throws an error.

As it is now I get this in the console:

Error: Request failed with status code 404 at e.exports (createError.js:16)
at e.exports (settle.js:17)
at XMLHttpRequest.x (xhr.js:66)

This is how I submit the mail:

        axios({
            method: 'POST',
            url: 'https://url.com/contact',
            data: formData
        }).then((response) => {
            if (response.data.status === 'success') {
                toast.success(
                    <div>
                        Success
                    </div>
                );
                resetForm();
            } else if (response.data.status === 'fail') {
                toast.error(
                    <div>
                        Error
                    </div>
                );
            }
        });

This is my server:

var express = require('express');
var cors = require('cors');
var router = express.Router();
var nodemailer = require('nodemailer');

app.use(express.static('build'));
app.get('*', (req, res) => {
    req.sendFile(path.resolve(__dirname, 'build', 'index.html'));
});

var transport = {
    service: 'gmail',
    auth: {
        user: '[email protected]',
        pass: 'my_password'
    }
};
var transporter = nodemailer.createTransport(transport);

transporter.verify((error, success) => {
    if (error) {
        console.log(error);
    } else {
        console.log('Server is ready to take messages');
    }
});

router.post('/contact', (req, res, next) => {
    var firstName = req.body.firstName;
    var lastName = req.body.lastName;
    var email = req.body.email;
    var phoneNumber = req.body.phoneNumber;
    var subject = req.body.subject;
    var message = req.body.message;
    var dataConsent = req.body.dataConsent;

    var content = `Name:n${
        firstName + ' ' + lastName
    }nnnEmail:n${email}nnnPhone Number:n${phoneNumber}nnnSubject:n${subject}nnnMessage:n${message}nnnConsent:n${dataConsent}`;

    var mail = {
        from: email,
        to: '[email protected]',
        subject: subject,
        text: content
    };

    transporter.sendMail(mail, (err, data) => {
        if (err) {
            res.json({
                status: 'fail'
            });
        } else {
            res.json({
                status: 'success'
            });
        }
    });
});

const app = express();
app.use(cors());
app.use(express.json());
app.use('/', router);
app.listen(3002);

And in package.json I run this script on start:

    "start": "node src/server.js",

I have this child component where you can submit a form, however, e.preventDefault() does not work

From the parent component. There are other forms, hence, there is a conditional form where it will used the child component’s form.

A user may click the button to show the form from the child component.

  const [isTrue, setIsTrue] = useState(false);
   <ButtonForm onClick={() => setIsTrue(true)}>
        Click for the Form
    </ButtonForm>

 {isTrue == true ? (
    <Form
        data={entryData}
        items={items}
        names={names}
            />
  ) : (
      ></>
    )}

This is the child component. The problem here is that, everytime I’ll submit it, it will reload the page:

const Form = ({ entryData, items, names }) => {
  const handleSubmit = (e) => {
    e.preventDefault();
    try {
      console.log(" saved");
    } catch (err) {
      console.log(err);
    }
  };

  return (
    <>
    
      <form onSubmit={handleSubmit}>
        //some codes here
        <Grid item>
          <TextField
            type="text"
            label="Item Number"
            variant="outlined"
            fullWidth
            required
          />
        </Grid>
       //some codes here
        <Grid item>
          <Button type="submit" fullWidth>
            Submit
          </Button>
        </Grid>
      </form>
      <br /> <br />
    </>
  );
};

export default Form;

How can i get value from promise array?

i have codes which has promise array

async function getResult(){
  ...
  //resultPromise  ==> it has promise in array Ex.[Promise { <pending> }, Promise { <pending> }]
  let finalResult = await resultPromise.map((result) => {
    //result has each promise from promise array
    result.then((obj) => {
      return obj.data
    })
  })
}

in here i want to get return obj.data for finalResult variable. How can i do that.
i tried below ways

return resultPromise.map((result)=>{
    result.then((obj)=>{
      console.log(obj.data)
      return obj.data
    })
  })

or

resultPromise.map((result)=>{
    result.then((obj)=>{
      console.log(obj.data)
      return obj.data
    })
  })

i know chaining way but, it couldn’t get value.

triggered the pseudo elements keyframe animation in jQuery

So I would like to animated this pseudo elements in a button by a jQuery but it is a pseudo element animation that triggered when hover. Here is the

DEMO.

And this is my code that wants to triggered the pseudo element animation but nothings happen after clicking it.

$('button').click(function() {
    $('.borders').toggleClass('s');
})

DEMO

Does anyone have idea please don’t vote me down. Thank you so much.

Using arguments to intialize services in a constructor

I have a constructor in a class which has certain arguments now i want to introduce a new service which should get intialized everywhere but doing it manually would be a hard task how do i do this intialization of new argument.

export class ResponseError {
  constructor(infoMessage: string, data?: any, errCode?: number) {
    this.success = false;
    this.message = infoMessage;
    this.data = data;
    this.errCode = errCode;
    Logger.warn(
      `${new Date().toString() 
        } - [Response]: ${ 
        infoMessage 
        }${data ? ` - ${  JSON.stringify(data)}` : ''}`,
    );
  }
}

Now i want to have a service intialized in it as well like:

  constructor(i18n: I18nService, infoMessage: string, data?: any, errCode?: number) {
     //...
}

How do i do this?? How do i initalize i18nService so that i do not have to manually write it everywhere.

Get object property value in an array in Javascript [duplicate]

i have an array of objects.

Lets say i got this array of objects from ezorArray:–

Array [
  Object {
    "EZOR": 19,
    "HIDDEN": "none",
    "HIDDEN_MOBILE": "none",
    "SECTION_MOBILE": "",
    "TEUR": "מידע נוסף לפי חוק הגנת השכר",
  },
  Object {
    "EZOR": 22,
    "HIDDEN": "none",
    "HIDDEN_MOBILE": "inline",
    "SECTION_MOBILE": "MisrotTlsList",
    "TEUR": "משרות",
    "eduInnerData": Array [],
    "listName": undefined,
  },
  Object {
    "EZOR": 23,
    "HIDDEN": "none",
    "HIDDEN_MOBILE": "inline",
    "SECTION_MOBILE": "TafkidimList",
    "TEUR": "תפקידים",
    "eduInnerData": Array [],
    "listName": undefined,
  },
  Object {
    "EZOR": 24,
    "HIDDEN": "none",
    "HIDDEN_MOBILE": "inline",
    "SECTION_MOBILE": "MiluyMakomList",
    "TEUR": "מילוי מקום",
    "eduInnerData": Array [],
    "listName": undefined,
  },
  Object {
    "EZOR": 25,
    "HIDDEN": "none",
    "HIDDEN_MOBILE": "inline",
    "SECTION_MOBILE": "HeadrutList",
    "TEUR": "העדרויות",
    "eduInnerData": Array [],
    "listName": undefined,
  },
]

i want to get the value of “SECTION_MOBILE” property of each object.

i have tried

ezorArray["SECTION_MOBILE"]

i got always undefined for each value.

But i want the values look like below one:–

MisrotTlsList
TafkidimList
MiluyMakomList
HeadrutList

How can get these values from an array?Thanks..